Rocket® Visual COBOL (formerly a Micro Focus® product)

 View Only
  • 1.  the connection reference between java and cobol

    Posted 01-22-2015 07:47
    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("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 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 (rs.next()) { 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
               end-exec
               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
                  else
                     display contact-name
                     display company-name
                  end-if
               end-perform
               exec sql close mycursor end-exec
               exec sql unbind connection myconnection end-exec
               goback.
    
           999-sql-error.
           
               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

    #connection
    #COBOLVISUALCOBOLMIGRATION
    #JVMCOBOL
    #Reference
    #VisualCobolManaged


  • 2.  RE: the connection reference between java and cobol

    Posted 01-22-2015 08:02

    add question:

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



  • 3.  RE: the connection reference between java and cobol
    Best Answer

    Posted 04-25-2015 15:14

    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.

         *jvmcobolから呼び出してdbを接続の場合、下記ようにを書かなければならない

           exec sql bind connection myconnection to :myconnection

           end-exec.

           IF SQLCODE NOT = 0

                DISPLAY "CONNECTION ERROR"SQLCODE

           END-IF.

           EXEC SQL UNBIND CONNECTION :myconnection

           END-EXEC.

    end method.