How do I set up JDBC to communicate with Oracle database?
Estimated Reading Time: 3 MinutesisCOBOL needs the proper JDBC driver to interact with any RDBMS, including Oracle. JDBC drivers are Java libraries (jar) that are usually supplied by the RDBMS vendor. Each RDMBS has its own drivers.
Oracle has several different types of drivers, and we recommend starting with the JDBC Thin driver. You can get Oracle's JDBC drivers here: http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html. Be sure to choose the one supported by your Java version.
The JDBC jar file needs to be accessible through the CLASSPATH variable. The easiest way to do this is to put it into the %ISCOBOL%jars folder that the runtime checks automatically.
The next requirement is to put the URL and driver name in your configuration file. Example values would be:
iscobol.jdbc.driver=oracle.jdbc.OracleDriver iscobol.jdbc.url=jdbc:oracle:thin:system/admin@localhost:1521:Check the documentation for more information about these two variables. You can also access samples in isCOBOL's sample directory, in the %ISCOBOL%samplesdata-accessesql directory and the %ISCOBOL%sampleeasydboracle directory.
Other helpful links are:
- An Oracle JDBC FAQ is at http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html
- The Oracle Database JDBC Developer's Guide is at http://docs.oracle.com/cd/E11882_01/java.112/e16548/toc.htm
- "Choosing the Appropriate Driver" is at http://docs.oracle.com/cd/E11882_01/java.112/e16548/overvw.htm#BABCHIGI
- You can find information in the isCOBOL Evolve SDK User's Guide under Programming Guides/JDBC
EXAMPLE
Here is a real example from one of our Linux boxes:
setup.sh:
export ISCOBOL_JDK_ROOT=/usr/jdk1.8.0_331 export PATH=$ISCOBOL_JDK_ROOT/bin:$PATH export ISCOBOL_JRE_ROOT=$ISCOBOL_JDK_ROOT export ISCOBOL=/home/dl136134/porting/Linux32/isCOBOL2012R1 export PATH=$ISCOBOL/bin:$PATH export LD_LIBRARY_PATH=$ISCOBOL/native/lib:$LD_LIBRARY_PATH export CLASSPATH=.:$ISCOBOL/lib/iscobol.jar:$ISCOBOL/lib/isxms.jar:$ISCOBOL/lib/utility.jar export ORACLE_HOME=/database/oracle/app/oracle/product/11.1.0/client_1 export CLASSPATH=$ORACLE_HOME/jdbc/lib/ojdbc6.jar:$CLASSPATH export PATH=$ORACLE_HOME/bin:$PATH export TWO_TASK=mach1Note that we are using TWO_TASK as documented at http://docs.oracle.com/cd/E11882_01/install.112/e24322/post_inst_task.htm#CHDJCCBI
and A tnsnames.ora entry and the following:
- tnsnames.ora file located in $ORACLE_HOME/network/admin
- The ORACLE_HOME environment variable set to this Oracle home
MACH1.PHX03.WEST.SUN.COM = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mach-1.phx03.west.sun.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = mach1) ) )which defines the mach1 service name.
To set up the environment run the following command:
../setup.shTo run a program named PROGRAM run the following command:
iscrun -c program.properties PROGRAMwhere program.properties contains the following:
iscobol.jdbc.driver=oracle.jdbc.OracleDriver iscobol.jdbc.url=jdbc:oracle:thin:user/password@//mach-1:1521/mach1replacing username/password with your actual username and password
In this example, mach-1 is the hostname and mach1 is the service name.
The syntax is:
Thin-style Service Name Syntax
Thin-style service names are supported only by the JDBC Thin driver. The syntax is:
@//host_name:port_number/service_name
For example:
jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicenameFor more information about the syntax of the connection URL see "Data Sources and URLs" at http://docs.oracle.com/cd/E11882_01/java.112/e16548/urls.htm#JJDBC28267