Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet not scrollable

 
Swatantra Yadav
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"));

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic