I am trying to create a Java program that accesses a ODBC datasource. Using the following code...
ODBCConnecton odbc = new ODBCConnection(); // This creates a connection to the ODBC datasource, which is returned by the getConn method.
Statement s = null;
ResultSet rs = null;
try {
s = odbc.getConn().createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
rs = s.executeQuery("select count(*) as rows from table");
if (rs.next()) {
System.out.print("Count of all rows is " + rs.getInt("rows"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtils.safelyClose(s, rs);
}
...I get the following exception:
java.sql.SQLException: Invalid Cursor Type.
at sun.jdbc.odbc.JdbcOdbcStatement.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.createStatement(Unknown Source)
at com.csc.remedyarchiver.data.input.ODBCConnection.main(ODBCConnection.java:38)
Originally, when I was attempting to resolve this on my own, I was using the empty argument createStatement() call but this lead to this exception (hence is why I used the FETCH_FORWARDS result set type):
java.sql.SQLException: The result set type is not supported.
at sun.jdbc.odbc.JdbcOdbcStatement.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.createStatement(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.createStatement(Unknown Source)
at com.csc.remedyarchiver.data.input.ODBCConnection.main(ODBCConnection.java:38)
Is there anything else I can try with this or does this need a different approach?
Thanks in advance.
ResultSet.CLOSE_CURSORS_OVER_COMMIT
parameter increateStatement()
to see if it helps – Darshan Lila 34 mins ago