Created On:  23 November 2012

Problem:

How do you get the DB2 JDBC JNDI database connection with Visual COBOL for Eclipse?

Resolution:

1. Introduction
This document covers working with OpenESQL applications under the Visual COBOL eclipse product lines, including some background on how things fit together, and an example of building and executing a sample program.
2. Software requirements
The document assumes that you already
Have a copy of Visual COBOL for Eclipse installed and licensed appropriately.
Have a copy of DB2 installed like db2 10.1 express version.
Have a copy of simple JNDI class library .jar file like simple-jndi-0.11.4.1.jar
3. DB2 COBOL example
   In Eclipse
   Create JVM project
   create cobol program TestDate
   Cut and paste the below program into the new program.
 
      $set sql(dbman=jdbc)
       program-id. TestDate as "TestDate".
 
       data division.
       working-storage section.
      
           exec sql include sqlca end-exec.
          
       01  hv-date pic x(10).
      
       01  hv-int  binary-long.
 
       procedure division.
 
           exec sql connect to sample end-exec
          
           exec sql
               select hiredate
               into :hv-date
               from employee
               where empno = 120
           end-exec
          
           move 999 to hv-int
          
           exec sql
               select days(:hv-date)
               into :hv-int
               from sysibm.sysdummy1
           end-exec
          
           display hv-date " = " hv-int " days"
          
           exec sql disconnect end-exec
 
           goback.
 
       end program TestDate.
 
4. JNDI sample.properties file
Create file sample.properties file in c:\JavaTools\config  that contains
 
type=javax.sql.DataSource
driver=com.ibm.db2.jcc.DB2Driver
url=jdbc:db2://localhost:50000/sample:retrieveMessagesFromServerOnGetMessage=true;
user=MYUSER
password=MYPASSWORD
 
5. JNDI jndi.properties file
Create file jndi.properties file in c:\JavaTools  that contains
java.naming.factory.initial=org.osjava.sj.SimpleContextFactory
# absolute directory, using the default file protocol
org.osjava.sj.root=C:\\JavaTools\\config\\
# must terminate property lines with newline
 
6. Eclipse project JVM Build path
db2jcc_license_cu.jar
db2jcc4.jar
JavaTools as an external class folder
simple-jndi-0.11.4.1.jar



7. Building and executing a sample program
We simply can set a debug break point on the connect statement, choose debug configuration.




And select debug, debug perspective and use step over to get to next line.



To look in more detail you would look at sqlcode, sqlstate this is just simple example.
But hope this gets you connected.

General query