Follow

Have two active JDBC Connections for a single ETP transaction?

Originally from ticket #1724.

Question

Hello, 

I need to manage to JDBC connection on the same application:

1) How can I select the database on EMBEDDED SQL STATEMENT.
2) How can I configure the ETP setting to manage 2 Database.

Answer

Elastic COBOL supports the IBM Enterprise COBOL (mainframe DB2) version of multiple database connections:

EXEC SQL 
SET CONNECTION { :host-variable | conn-name }
END-EXEC

where host-variable is defined as a PIC X(16) which evaluates to a database connection name or where conn-name is an unquoted database connection names. SET CONNECTION will set the default connection name until the next SET CONNECTION. If no SET CONNECTION is executed then "default" is the database connection name. Database connection names and their attributes are set in the SQL tab of the ETP Settings.

For example, referring to the following picture:

etp-sql-tab.png

The following sequence will insert "1" and "3" into table "a" of the "default" database and "2" into table "b" of the "gary" database.

10 WS-CONN PIC X(16). 
...
EXEC SQL
INSERT INTO A VALUES(1)
END-EXEC
MOVE 'GARY' TO WS-CONN. 
EXEC SQL
SET CONNECTION :WS-CONN
END-EXEC
EXEC SQL 
INSERT INTO B VALUES(2)
END-EXEC
EXEC SQL 
SET CONNECTION DEFAULT
END-EXEC
EXEC SQL 
INSERT INTO A VALUES(3)
END-EXEC

An ETP transaction showing this interaction is also attached. BMSESQL.BMS is the screen image for the transaction ETPESQL.CBL. Define a COBOL project with compatibility "ETP Transaction Template" attached with each file. Then, create a ETP Project with sysid "etp" and define programs "etpesql" and transaction "init" that maps to it. Export the project with the ETP Export Wizard to an ear file and deploy to an JEE Application Server and access with URL http://localhost:8080/etp/servlet.  The transaction screen is below:

etp-sql-scr.png

For more information, see the Elastic Transaction Platform Programmers Guide, page 12.

 

Extension

Also supported is an Elastic Transaction Platform extension to the SET CONNECTION statement,

EXEC SQL 
SET CONNECTION java.sql.Connection-object
END-EXEC

where java.sql.Connection-object is an instantiated Java object (native Java variable or MOVEd into a COBOL variable) that is of class type java.sql.Connection.

 

 

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk