Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

rs.beforeFirst() exception

 
varkala prabhakar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai all,
when i try to use the beforeFirst function i get the following error. Request to all to help me where to correct my program.
thanx
prabhakar.
-----------------------------------------------------
java.sql.SQLException: Invalid operation for forward only resultset : beforeFirst
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.driver.BaseResultSet.beforeFirst(BaseResultSet.java)
at dbtest1.main(dbtest1.java:26)
--------------------------------------------------------
import java.io.*;
import java.util.*;
import java.sql.*;
public class dbtest1 {
public static void main(String args[]) {
Connection con;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(Exception e) {
System.out.println(" ERROR: While Getting Connection with the First Database");
e.printStackTrace();
}
try {
con = DriverManager.getConnection("jdbc racle:thin:@202.141.81.233:1521:PROJDB","scott","tiger");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp");

for(int i=0;i<5;i++)
{
rs.beforeFirst();
while(rs.next()){
System.out.println(""+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getInt(4)+"\n");
}
}
}
catch(Exception e) {
e.printStackTrace();
}

}

}
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What it's saying is that you can only move forward in your resultset. If you are using JDBC 2.0 and above API, you need to specify constants if you want to move in both directions. The default is FOWARD_ONLY if you don't specify anuthing. Check the API for how to use the constants.
------------------
Bosun
SCJP for the Java� 2 Platform
 
Rajesh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai
in ur program u r using jdk 1.3 method so instead of using like this..
Statement stmt = con.createStatement();
use like this...
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
then try
and give me the reply
Thankyou VeryMuch
Yours
Rajesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic