java.sql.SQLException:Exhausted Resultset错误

use*_*123 3 java sql jdbc resultset

我遇到了这个异常的问题java.sql.SQLException:以下代码中的Exhausted Resultset.我确定我的查询只返回一个值.即使我不使用rs.next(); 它抛出错误 java.sql.SQLException:未调用ResultSet.next.能否请你帮忙?

仅供参考,我正在使用另一个来自另一个类的menthod的主要结果集.会影响吗?

谢谢

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;
Run Code Online (Sandbox Code Playgroud)

Jåc*_*cob 5

试试吧

if (rs! = null) { 
 while (rs.next()) {
  returnValue = rs.getString("display_name");
}
......
Run Code Online (Sandbox Code Playgroud)