Skip to main content

Problem:

The demo attached contains 3 programs

One Java program which does SQL I-Os thru JDBC

One OO COBOL program which invokes the Java program above

              ( this OO COBOL program is a 'stub' between procedural COBOL and JAVA )

One procedural COBOL program which invokes the OO COBOL program above.

Resolution:

=======================

INTRODUCTION_1:

since the JAVA program does SQL I-Os using JDBC using an ODBC layer,

you need a DSN (Data Source Name ) called 'NetExpress Sample2' pointing to an ACCESS DataBase named SAMPLE.MDB ( delivered with .ZIP attached with this demo )

--> Config Panel->Administration tools->ODBC data sources

IF the DSN 'NetExpress Sample2' does'nt exist, create it

using an ACCESS Driver pointing to ACCESS DataBase named SAMPLE.MDB

=======================

INTRODUCTION_2:

As described above, the demo contains 3 programs

a Java one

named

Java_Jdbc_Access.java

a OO COBOL one

named

OOCOBOL.cbl

a procedural COBOL one named

proceduralCOBOL.cbl

in the FULL demo, proceduralCOBOL calls OOCOBOL which invokes Java_Jdbc_Access

Anyway, for test purposes, each program can be launched as a launcher

eg:

java Java_Jdbc_Access

runm OOCOBOL

runm proceduralCOBOL

=======================

STEP_1:

running the first STEP of the demo eg: java Java_Jdbc_Access

What does the Java code Java_Jdbc_Access do?

---->

First, open a Netx command prompt SET JAVA environment

Doc NE 4.0->Distributed Computing->Part 3: Java and COBOL->Overview&Setting Up the

       Environment for Java and COBOL

http://supportline.microfocus.com/documentation/books/nx40/dipubb.htm

---->Java code: Java_Jdbc_Access

method main

updates public variables JDBC url & UserID & password

updates the SQL query which will be runned against the database

invokes a method named SQLIO()

closes the opened JDBC connection invoking the method CloseConnectionJDBC()

method SQLIO

loads the JDBC driver invoking the method JdbcOdbcDriverAvail()

opens a JDBC connection invoking the method getConnectionJDBC()

invokes the method doSQLQuery to proceed I-Os against the database

method doSQLQuery

creates a JDBC statement

[stmt = this.con.createStatement();

]

executes this statement

[ResultSet rs = stmt.executeQuery(SQLquery);]

note the result of the execution of this statement is returned in a ResultSet

which contains a "Collection" of rows of a table

saves the ResultSet just retrieved above in the public variable rs [this.rs = rs;]

displays the content of the ResultSet invoking the method displayResultSet(rs);

---->

Compile the java program Java_Jdbc_Access.java ( javac Java_Jdbc_Access.java )

run it: java Java_Jdbc_Access

The content of the table Customer should be displayed

                        ( as in file Java_Jdbc_Access.log ... ( delivered with .ZIP attached with this demo )

=======================

STEP_2:

running the second  STEP of the demo eg: runm OOCOBOL

-->first,in OOCOBOL.CBL, have the constant CALLERMODE()

set

--->

$SET constant CALLERMODE()

   [ character $ in column 7 )

-->Cobol code  OOCOBOL in launcher mode

creates an instance of the class Java_Jdbc_Access

(Comment 1)

updates public variables JDBC url & UserID & password

(Comment 1)

updates the SQL query which will be runned against the database

(Comment 1)

invokes a method named SQLIO()

(Comment 1)

invokes a method getrs to return the ResultSet retrieved in the method SQLIO()

!!!! Doc NE 4.0->Distributed Computing->Chapter 10: Calling Java from OO

COBOL->Accessing Java Variables

                    

No need of hand written methods to access Java Static | public variables !!!

remember, as documented above

(method doSQLQuery .... saves the ResultSet just retrieved above in the public

variable rs [this.rs = rs;]

)

invokes Java methods on the ResultSet to retrieve its content and displays the content

closes the opened JDBC connection invoking the method CloseConnectionJDBC()

*

               (Comment 1

* As int the main method of Java_Jdbc_Access

-->

Compile OOCOBOL ( COBOL OOCOBOL int() anim;

launch OOCOBOL   rumm oocobol

The content of the table Customer should be displayed

( as in file oocobol..log ... ( delivered with .ZIP attached with this demo )

=======================

STEP_3:

running the full demo eg: proceduralCOBOL calls OOCOBOL which invokes Java_Jdbc_Access

-->first,in OOCOBOL.CBL, have the constant CALLERMODE()

unset

--->

*SET constant CALLERMODE()

   [ character * in column 7 )

-->The only difference in OOCOBOL program depending on it's used in caller mode or called mode is  

in caller mode:

the result of the SQL query is displayed on the screen

in called mode, the result of the SQL query is put in a LINKAGE group

-->Cobol code  proceduralCOBOL

calls OOCOBOL passing to it 2 variables

1st one, named NumberOfRowsReturned, will contain when back from OOcobol in  

       proceduralCOBOL the number of table's rows rerurned

2nd one, named DCLcustomer which is a group with OCCURS, contains data retrieved

       by the SQL query

display the content of the SQL data returned, displaying the content of the group

DCLCUSTOMER which contains data returned following the SQL I-Os

-->

Compile proceduralCOBOL ( COBOL  proceduralCOBOL  int() anim;

launch  proceduralCOBOL:    rumm proceduralCOBOL

The content of the table Customer should be displayed

( as in file proceduralCOBOL..log ... ( delivered with .ZIP attached with this demo )

=======================

STEP_4

For convenience, a Net Express project is delivered with this demonstration

:

=======================

You can see the JAVADOC of this demonstration in the subdir JAVADOC

after you unzipped the COBOtoJava_jdbc.zip

=======================

Attachments:

CobolToJava_JDBC.zip

Old KB# 3954