Hi, I would think that if(rs != null){ // code block } would send you into the code block ... isnt there always a resultset returned even if there are no records. but i would also think that if (rs.next()){ // code block } SHOULD not let you into the code block if you have no results.
will never be true. The executeQuery() method always return a ResultSet object or throws a SQLException which will cause it to immediately jump to the exception block of code anyways. Jamie
If you could please show us the entire code block and not just one line, then we might be able to help better. Keep in mind that if you are still doing this:
Because of the (rs != null) part, it will drop into the block because, as Jamie already mentioned, executeQuery will always return a ResultSet object or throw an exception.
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rs =st.executeQuery("union query here"); //which retrieves more than one record if (rs.next()==true) {
Originally posted by Vasudevan Gopalan: Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rs =st.executeQuery("union query here"); //which retrieves more than one record if (rs.next()==true) {
rs.beforeFirst(); while(rs.next()) { .... }
}
What if you don't use the IF statement at all? What if you just use the while(rs.next()) { } Unless you have an ELSE clause with your IF, there is no need for the IF.
Also, in your while block, do not reuse the same statement that you created your resultset with or the resultset will also be closed automatically. eg.
also, please use the code tags to keep your code readable to others! Jamie
Post by:autobot
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, the permaculture playing cards