[Migrated content. Thread originally posted on 24 November 2010]
Hi All,I am trying to access AcuCOBOL vision files from java using AcuODBC. I am using AcuBench 6.2. My files are in a Unix Server.
I have successfully created DSN using srvconfig.sh script.
And I tried the following java code.
import java.net.URL;
import java.sql.*;
class JDBCapp {
static Connection theConn;
public static void main (String args[]) {
try {
theConn = MyConnection.getConnection();
ResultSet rs;
Statement stmt;
String sql;
sql = "select * from t_invstk";
stmt = theConn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getString(2));
}
rs.close();
stmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (theConn != null) theConn.close();
}
catch (Exception e) {
}
}
}
}
class MyConnection {
public static Connection getConnection() throws Exception {
Driver d = (Driver)Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
/*
Connection c = DriverManager.getConnection(
"jdbc:odbc:Driver={AcuODBC Driver};DBQ=/IMOSDATA/XFD;"
);
return c;
*/
// To use an already defined ODBC Datasource :
Connection c = null;
String URL = "jdbc: odbc: DSN";
try
{
c = DriverManager.getConnection(URL, "user", "pwd"); }
catch (Exception ex)
{
ex.printStackTrace();
System.out.println(ex.getMessage());
}
return c;
}
}
But I unable to establish the connection with the data source.
Please help. Thanks.
--Mano



