Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

the connection reference between java and cobol

$
0
0
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

Viewing all articles
Browse latest Browse all 4356

Trending Articles