problem with resultset
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jack_robinson
Posted On:   Thursday, February 14, 2008 04:29 AM

Hello friends, I am using jdbc connectivity to access database. con = DriverManager.getConnection("jdbc:odbc:MyDB","system","manager"); stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE ); ResultSet rs=stmt.executeQuery("select * from Users where userid like 'xyz' "); In Users table there is no user with userid='xyz' , but when I executes statement boolean b=rs.first(); b returns true but it should return false and when I try to execute String str=rs.getString(1); It gives exception "Invalid cursor state"    More>>

Hello friends,

I am using jdbc connectivity to access database.


con = DriverManager.getConnection("jdbc:odbc:MyDB","system","manager");

stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE );

ResultSet rs=stmt.executeQuery("select * from Users where userid like 'xyz' ");


In Users table there is no user with userid='xyz' , but when I executes statement



boolean b=rs.first();



b returns true but it should return false and when I try to execute



String str=rs.getString(1);



It gives exception "Invalid cursor state"


Please help me and tell me why Resulset is showing that one row is present in Resultset and how to solve this problem

   <<Less

Re: problem with resultset

Posted By:   Stephen_McConnell  
Posted On:   Thursday, February 14, 2008 09:39 AM

Could it be possible that the

boolean b = rs.first();

is attempting to set the cursor to the first element in the result set, but since there is none, it returns an invalid cursor state when you try to access it.


I have a tendency to use something like...


if(rs.next()){
String str = rs.getString(1);
}

In almost all implementations, this will give a false return when there is no ResultSet.


Like Robert says, it seems to be a bad implementation of the driver. Try using something besides a JDBC/OBDC driver if there is one available.


Stephen McConnell

Re: problem with resultset

Posted By:   Robert_Lybarger  
Posted On:   Thursday, February 14, 2008 08:38 AM

Note same question is discussed over here. But it sounds like the driver being used (which wasn't disclosed in initial post) is just bad.
About | Sitemap | Contact