title: java.sql.SQLException: Exhausted Resultset error
body: <p>I'm facing the problem with this exception <strong>java.sql.SQLException: Exhausted Resultset</strong> in following code. I'm sure my query returns only one value. Even If I don't use <strong>rs.next();</strong> it throws the error  <strong>java.sql.SQLException: ResultSet.next was not called</strong>. Could you please help?</p>
  
  <p>FYI, I'm using the another result set in main where this menthod from another class is called. will it affect?</p>
  
  <p>Thanks</p>
  
  <pre><code>public static String getdispname(Connection conn, String resname) 
  throws SQLException, Exception {
  
              //String resname = "";
              String returnValue = "";
              String querystring = "";
  
              //Query to select the displayname from resid
  
              querystring += "select distinct display_name";
              querystring += " from cust_rally_team_member";
              querystring += " where display_name like '%"+ resid +"%'";
  
              // Create select statement
              Statement stmt = conn.createStatement();
  
              try {
                  // Execute statement
                  ResultSet rs = stmt.executeQuery(querystring);
                  if (rs!= null) { 
              while (rs.next()) {
              returnValue = rs.getString("display_name");
              } catch (SQLException ex) {
                  throw new SQLException(ex);
              } catch (Exception ex) {
                  throw new Exception(ex);
              }
              // Close statement
              finally {
                  stmt.close();
              }
  
              return returnValue;
  </code></pre>