This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes rs.beforeFirst()  exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "rs.beforeFirst()  exception" Watch "rs.beforeFirst()  exception" New topic
Author

rs.beforeFirst() exception

varkala prabhakar
Ranch Hand

Joined: Sep 08, 2001
Posts: 54
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

Joined: Nov 06, 2000
Posts: 1510
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


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
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
 
 
subject: rs.beforeFirst() exception
 
Similar Threads
Accesing Excel data sheets through JDBC
Connecting to Excel thru JDBC
jdbc in Unix
Scrollable Result Sets
Class.forName()