Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
check changing if to while.just telling while (rs.next()) { System.out.print("Count of all rows is " + rs.getInt("rows")); } –  Piumi Wandana 36 mins ago
    
@PiumiWandana - That didn't work with the Invalid Cursor Type exception. –  Ocracoke 35 mins ago
    
Try adding ResultSet.CLOSE_CURSORS_OVER_COMMIT parameter in createStatement() to see if it helps –  Darshan Lila 34 mins ago
    
Try s = odbc.getConn().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); –  Sunny 31 mins ago
    
@DarshanLila - Adding that threw a java.lang.UnsupportedOperationException exception. –  Ocracoke 26 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.