Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Sep 2009
Posts: 2
#1: Sep 15 '09
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
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Sep 16 '09

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


Perhaps an exception is being thrown. Put a println in your catch block and see if it executes.
Newbie
 
Join Date: Sep 2009
Posts: 2
#3: Sep 16 '09

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


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?
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Sep 17 '09

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


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.
Reply