Using Op-codes to get a ResultSet Object

Another way to access JDBC ResultSet objects is to issue a call to the C$JAVA routine using the op-codes CJAVA-DBCONNECT and CJAVA-DBQUERY. To do this, you must include the "java.def" file that comes with ACUCOBOL-GT in the COBOL program's working storage section. "java.def" is located in the sample/def directory where you installed ACUCOBOL-GT.

This method is somewhat more efficient than using the CVM's DBConnect class, because the Connection and ResultSet handles do not have to be created prior to being used. Here is an example of using the op-codes:

MOVE "sun.jdbc.odbc.JdbcOdbcDriver" to DB-DRIVERSTR

MOVE "jdbc:odbc:DefaultDir=D:\\cobol7\\bin;Driver={Microsoft Text Driver (*.txt; *.csv)};DriverId=27;UID=admin;Initial Catalog=D:\\cobol7\\bin" to DB-CONNECTSTR

MOVE "SELECT * FROM dataFile.csv" to DB-QUERY.
    
CALL "C$JAVA" USING CJAVA-DBCONNECT, DB-DRIVERSTR, DB-CONNECTSTR GIVING DB-CONNECT.
     
CALL "C$JAVA" USING CJAVA-DBQUERY DB-QUERY, DB-CONNECT GIVING DB-RESULTSET.

CALL "C$JAVA" USING CJAVA-CALL, DB-RESULTSET, "java/sql/ResultSet", "next", "()Z", FIELD-BOOLRET GIVING STATUS-VAL.

CALL "C$JAVA" USING CJAVA-CALL, DB-RESULTSET, "java/sql/ResultSet", "getRow", "()I", FIELD-RET GIVING STATUS-VAL.
     
MOVE 1 to FIELD-INT.
    
CALL "C$JAVA" USING CJAVA-CALL, DB-RESULTSET, "java/sql/ResultSet", "getString", "(I)X", FIELD-INT, FIELD-STRINGRET GIVING STATUS-VAL.

CALL "C$JAVA" USING CJAVA-DELETE, DB-CONNECT GIVING STATUS-VAL.

CALL "C$JAVA" USING CJAVA-DELETE, DB-RESULTSET GIVING STATUS-VAL.