Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good evening, guys,

I've just come across an issue on a ResultSet returned from a PreparedStatemnt.
next() function of ResultSet hangs if I set the parameter with setString() like below.


Java
PreparedStatemnt ps = null;
ResultSet rs = null;
ps = con.prepareStatemnt("select id from Table1 where name = ?");
ps.setString(1, "Bob");

rs = ps.executeQuery();   // OK here

if(rs.next()){            // hangs here

}





However, it works fine if I do not set the parameter and concatenate the parameter to the query like this,

Java
PreparedStatemnt ps = null;
ResultSet rs = null;
ps = con.prepareStatemnt("select id from Table1 where name = 'Bob' ");

rs = ps.executeQuery();   // OK here

if(rs.next()){            // OK now

}




I've applied these two methods to two same table, one with 100 records and the other with 10 million records.
Setting the parameter worked on small table, but the large table.
Concatenating the parameter to the sql query string worked on both.

Is this a bug? or am I missing something important?

regards,
Posted
Comments
Richard MacCutchan 26-Oct-13 12:23pm    
See ResultSet.next() for correct usage. You should use your debugger to check what is actually being returned from the query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900