the connection reference between java and cobol

Java program: 

import java.sql.*; public class javamain { /** * @param args * @throws SQLException */ public static void main(String[] args) throws SQLException { // Create a variable for the connection string. String connectionUrl = "jdbc:sqlserver://localhost:1433;" "databaseName=Northwind;user=chris;password=mypassword"; // Declare the JDBC objects. Connection con = null; Statement stmt = null; ResultSet rs = null; try { // Establish the connection. Class.forName(""); con = DriverManager.getConnection(connectionUrl); // Create and execute an SQL statement that returns some data. String SQL = "SELECT TOP 10 * FROM Customers"; stmt = con.createStatement(); rs = stmt.executeQuery(SQL); // Iterate through the data in the result set and display it. while ( { System.out.println(rs.getString(1) " " rs.getString(2)); } cobolclass cc = new cobolclass(); cc.cobolclass(con); } // Handle any errors that may have occurred. catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) try { rs.close(); } catch(Exception e) {} if (stmt != null) try { stmt.close(); } catch(Exception e) {} if (con != null) try { con.close(); } catch(Exception e) {} } } }

cobol program:

  $set sql(dbman=jdbc) ilsmartlinkage
       program-id. cobolclass as "cobolclass".

       data division.
       working-storage section.
       exec sql include sqlca end-exec.
       01 contact-name   string.
       01 company-name string.
       linkage section.
       01 myconnection object.
       procedure division using by value  reference myconnection.
           exec sql whenever sqlerror
              perform 999-sql-error
           exec sql bind connection to :myconnection end-exec
           exec sql declare mycursor cursor for select ContactName, CompanyName from Customers end-exec
           exec sql open mycursor end-exec
           perform until exit
              exec sql fetch mycursor into :contact-name, :company-name end-exec
              if sqlcode = 100
                 display "no more"
                 exit perform
                 display contact-name
                 display company-name
           exec sql close mycursor end-exec
           exec sql unbind connection myconnection end-exec

           display "error = " sqlcode
           display sqlerrmc.
       end program cobolclass.

here,after change "value" to "reference", an error is happened "class cobolclass method cobolclass(ObjectRef) type ObjectRef is not exsit "
now , how to deal with it
  • add question:

      how to do the sql transation between java and cobol(jvm)/cobol

  • Verified Answer

    this is right source and tested.

    -------------------------------------jvm cobol source-----------------------------------------------------------------------

    method-id execute.

          local-storage section.

          linkage section.

          01 myconnection object.

          01 WK-TEST PIC X(9).

          procedure division using by value myconnection.


           exec sql bind connection myconnection to :myconnection


           IF SQLCODE NOT = 0



           EXEC SQL UNBIND CONNECTION :myconnection


    end method.