wood burning stoves 2.0*
The moose likes JDBC and the fly likes ResultSet not scrollable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet not scrollable" Watch "ResultSet not scrollable" New topic
Author

ResultSet not scrollable

Swatantra Yadav
Greenhorn

Joined: Aug 29, 2000
Posts: 9
I am using jdk1.2.2, Oracle 8i with Oracle jdbc classes12.zip driver
I create a result set as below:
_____________________________________________
Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
__________________________________________________

I expect that my result set will be scollable.
I can iterate my result set object in a while
and again come back to the first first row (call first() or beforeFirst() followed by next();
However the above code fails at runtime.
Any suggestions... I do believe that jdk1.2.2 does support jdbc 2.0 - correct me if I am wrong. I guess it must be because I am using old driver. Please tell me if you know which driver would fix this problem.
Thanks,
Swatantra.
Swatantra Yadav
Greenhorn

Joined: Aug 29, 2000
Posts: 9
I am using jdk1.2.2, Oracle 8i with Oracle jdbc classes12.zip driver
I create a result set as below:
_____________________________________________
Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
__________________________________________________
I expect that my result set will be scollable.
I canNOT iterate my result set object in a while
and again come back to the first first row (call first() or beforeFirst() followed by next();
The above code fails at runtime.
Any suggestions... I do believe that jdk1.2.2 does support jdbc 2.0 - correct me if I am wrong. I guess it must be because I am using old driver. Please tell me if you know which driver would fix this problem.
Thanks,
Swatantra.
Gopi Padmanabhan
Greenhorn

Joined: Aug 16, 2001
Posts: 2
Please understand that JDK 1.2.2 is one thing and JDBC 2 is another. The possibility is that you may have JDK 1.2.2 classes
but your driver may not support JDBC 2. So please ask your support group if the current driver supports JDBC 2. Thanks
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

The combination of jdk 1.2.2 and classes12.zip do support jdbc 2.0(it is the same development environment as mine). I you recently upgraded from a lower jdk or upgraded from classes111.zip check your classpath to ensure that your most updated drivers and jdk have replaced the old.
by the way, if you could elaborate on "The above code fails at runtime"(ie. error messages) it might help out a little more to pin down a solution.
Jamie
Swatantra Yadav
Greenhorn

Joined: Aug 29, 2000
Posts: 9
Thanks guys. Actually I must have been doing something wrong last time. The result set _does_ scroll as well update database as long as following is done:
Statement stmt = conn.createStatement(
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_UPDATABLE);
Jamie if remove the 2 arguments in createStatement I get this error at Run time:
java.sql.SQLException: Invalid operation for forward only resultset : beforeFirst at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156) at oracle.jdbc.driver.BaseResultSet.beforeFirst(BaseResultSet.java:56) at com.camilion.rdbms.TestJavaResultSet.main(TestJavaResultSet.java:29) TestJavaResultSet: Invalid operation for forward only resultset : beforeFirst
But with the arguments EVERYTHING works just fine. I dont even need another driver or jdk!!
code:
Statement stmt = conn.createStatement();
java.sql.ResultSet rs = stmt.executeQuery("SELECT CODE, DESCRIPTION FROM AM_LKP_CYCLE");
// rs will be scrollable, will not show changes made by others,
// and will be updatable
int count = 0;

while (rs.next())
{
++count;
System.out.println ("TestJavaResultSet: Record #"+ count +" " + rs.getString("CODE"));
}

count = 0;
rs.beforeFirst();
while (rs.next())
{
++count;
System.out.println ("TestJavaResultSet: Record #" + count + " " + rs.getString("DESCRIPTION"));


}
Swatantra Yadav
Greenhorn

Joined: Aug 29, 2000
Posts: 9
Oops pasted the wrong code. Here is the right version that works:
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
java.sql.ResultSet rs = stmt.executeQuery("SELECT CODE, DESCRIPTION FROM AM_LKP_CYCLE");
// rs will be scrollable, will not show changes made by others,
// and will be updatable
int count = 0;

while (rs.next())
{
++count;
System.out.println ("TestJavaResultSet: Record #"+ count +" " + rs.getString("CODE"));
}

count = 0;
rs.beforeFirst();
while (rs.next())
{
++count;
System.out.println ("TestJavaResultSet: Record #" + count + " " + rs.getString("DESCRIPTION"));

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet not scrollable