LegacyJ CICS and COBOL technology for the J2EE Enterprise Environment

Products     Services     Support     Sales     News     Partners

Academic
Programs

Customer
Information

News &
Information

Technical
Information

White
Papers

About Us

LegacyJ FAQ

Making the SQL driver available to PERCobol:

The JDBC (Java DataBase Connectivity) driver must be available to therunning program. The JDBC driver is specific to the database, in this case SQL, and these JDBC drivers come from the database vendor such as IBM or Oracle. It will be a file ending in .zip or .jar (do not extract it). The filename for it changes over time, so check your database release's documentation.

To make the driver available to a PERCobol project within the IDE, right-click the project, select Properties. This is where the Cobol and Java settings for the project are available. Since this is an element of Java functionality being exposed to PERCobol, select Java Build Path. The libraries tab lists all Java libraries available to the program. Using the 'External JARs' button, add the SQL JDBC driver library to the project. It's now available to the program at runtime.

While in the properties, select Cobol Compiler Settings from the left.

Select Category SQL. In the JDBC tab is Enable enhancements for SQL SQL/JDBC; check it.

Making the SQL connection:

To enable it from the program, you must connect to the database before you may use it. The typical connection statement is of the form:


EXEC SQL
CONNECT TO jdbc:SQL://host:6789/dbname
USER :uid
PASSWORD :pwd
DRIVER COM.ibm.SQL.jdbc.net.SQLDriver
SERIALIZABLE
END-EXEC

The CONNECT TO piece is the URL for the connection as documented in the SQL JDBC manual. It always begins with jdbc:. The SQL: specifies which driver to use. The host is the hostname location of the database. 6789 is the default port for SQL, but if you have SQL using another port change it. And dbname is specific to your setup.

:uid and :pwd are just Cobol host variables. They may be specified
directly if desired, although the user is often prompted for password so host variables are most often used.

The DRIVER specifies the classname of the JDBC driver. The classname is given in the JDBC driver's documentation, usually by showing a snippet of Java code Class.forName("drivername"); JDBC is often not documented well. The driver listed above is often the most common SQL remote driver name. (SQL local to the machine has a faster driver with a separate name; there are often two included with SQL, one remote and one local.)

SERIALIZABLE is an option, but used quite often.

The connection to SQL from within an application server will be a little different, but all changes are encapsulated within the connect
statement. If running in a managed environment such as an application server where it says a DataSource is available, the CONNECT TO piece is just ds:name where name is exported by the application server and the driver clause is not required.

PERCobol SQL general:

SQLCODE and SQLSTATE can be any definition sufficient to hold the data, such as PIC S999 and PIC X(5). Their usage clauses don't matter.

When creating a new program, you can select SQL Program as a template to give a basic reminder of the SQL uses.

PERCobol

Home         About Us         Privacy        Legal        
© Copyright LegacyJ Corp. 1998, 2005
All Rights Reserved.

All trademarks are the properties of their respective owners or licensers.