I am trying to create a Java program that accesses a ODBC datasource. Using the following code...
Connection conn;
try {
Driver d = (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
DriverManager.registerDriver(d);
String URL = "jdbc:odbc:AR System ODBC Data Source";
conn = DriverManager.getConnection(URL);
} catch (SQLException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
Logger.error(this, e);
}
Statement s = null;
ResultSet rs = null;
try {
s = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 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: 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)
Originally, when I was attempting to resolve this on my own, I was using the empty argument createStatement() call but this lead to the above exception (hence is why I used the TYPE_FORWARD_ONLY result set type but still the same result):
Is there anything else I can try with this or does this need a different approach?
ResultSet.CLOSE_CURSORS_OVER_COMMITparameter increateStatement()to see if it helps