Tuesday, 10 September 2013

JAVA ODBC scroll error despite TYPE_SCROLL_SENSITIVE

JAVA ODBC scroll error despite TYPE_SCROLL_SENSITIVE

I have a JAVA project involving a ODBC database query in which I need to
move the cursor in the result set. I've declared the type of ResultSet to
be TYPE_SCROLL_SENSITIVE, but when I execute the script I get an exception
stating the ResultsSet type is TYPE_FORWARD_ONLY. I've pasted my
(simplified) project code below, and would appreciate any help.
import java.util.InputMismatchException; //Necessary package for basic
Java utilities
import java.sql.*; //Necessary packages for SQL
routines
public class test {
public static void main(java.lang.String[] args) throws Exception {
// declare variables & create database connection
System.out.println("Open ODBC Connection....");
Connection dataConnection = DriverManager.getConnection("jdbc:odbc:DSN");
Statement stmt =
dataConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
int i = 0;
int N = 0;
//loading JDBC-ODBC Bridge driver into memory
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// create SQL query string
String sql = "SELECT ObjRef, IDX, DateListDateAsString FROM
ARRAY_BAC_CAL_DateList WHERE DEV_ID=10000 AND INSTANCE=1";
// run the query
ResultSet rs = stmt.executeQuery(sql);
// determine number of date entries
rs.last();
N = rs.getInt("IDX");
// close connection
rs.close();
dataConnection.close();
System.out.println ("Connection closed\n");
}
}
The error I receive is:
"Exception in thread "main" java.sql.SQLException: Result set type is
TYPE_FORWARD_ONLY at
sun.jdbc.odbc.JdbcOdbcResultSet.last(JdbcOdbcResultSet.java:2290) at
test.main(test.java:26)
Line 26 is where I try to move the result set cursor.
Again, any help would be appreciated.

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog.
    Really very informative post you shared here. Kindly keep blogging.
    If anyone wants to become a Java developer learn from Java Training in Chennai.
    or learn thru Java Online Training in India .
    Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete