468,527 Members | 2,091 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,527 developers. It's quick & easy.

rs.next() returns true, but if (rs.next()) block not executed

In the following method:

Expand|Select|Wrap|Line Numbers
  1. public boolean isMemberAlive(String userSsn) throws SQLException 
  2. {
  3.     boolean isMemberAlive = false;
  4.  
  5.     Connection c = null;
  6.     Statement s = null;
  7.     ResultSet rs = null;
  8.  
  9.     String strSQL = "SELECT Count(*) AS RecordCount " +
  10.         "FROM crs.memmst " +
  11.         "WHERE memmst_ssn = '" + userSsn + "' AND " +
  12.             "(memmst_dt_death IS NULL OR 
  13.             TRIM(memmst_dt_death) = '')";
  14.  
  15.     try 
  16.     {
  17.         c = CnxOracle.getConnection(schema, schemapwd);
  18.         s = c.createStatement();
  19.         rs = s.executeQuery(strSQL);
  20.  
  21.         if (rs.next()) 
  22.         {
  23.             if (rs.getInt("RecordCount") > 0)
  24.             {
  25.                 isMemberAlive = true;
  26.             }
  27.         }
  28.     }
  29.     catch (SQLException exception)
  30.     {
  31.         recordException(exception);
  32.     }
  33.     finally 
  34.     {
  35.         rs.close();
  36.         s.close();
  37.         c.close();
  38.  
  39.         rs = null;
  40.         s = null;
  41.         c = null;
  42.     }
  43.  
  44.     return isMemberAlive;
  45. }
  46.  
At line #21... if (rs.next()) - the resultset contains a record, rs.next() returns true (I checked using a breakpoint), but the statements in the if block are not executed. The code jumps immediately to the finally block.

This is happening in several (new) methods I've written, but older methods containing similar logic / syntax are working fine.

What is wrong???

Thanks,
Woody
Sep 15 '09 #1
3 8492
r035198x
13,262 8TB
Perhaps an exception is being thrown. Put a println in your catch block and see if it executes.
Sep 16 '09 #2
Nope... I put println statements in the if block and the catch block - not executing either of 'em. <sigh>

I'm playing around with Connection scoping, now... I wonder if using these similarly-named connections / statements / resultsets within multiple methods, within multiple DAO's might be introducing a conflict?
Sep 16 '09 #3
r035198x
13,262 8TB
Well if the code is not getting into the if for rs.next() then it means that rs.next() returned false. You made a mistake in your debugging.
Sep 17 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by John Moore | last post: by
59 posts views Thread by Pierre Quentel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.