gpt4 book ai didi

java.sql.SQLException : Exhausted Resultset error 异常

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:46:28 26 4
gpt4 key购买 nike

我在以下代码中遇到此异常 java.sql.SQLException: Exhausted Resultset 的问题。我确信我的查询只返回一个值。即使我不使用 rs.next();,它也会抛出错误 java.sql.SQLException: ResultSet.next was not called。你能帮忙吗?

仅供引用,我在 main 中使用另一个结果集,其中调用了另一个类的这个方法。会影响吗?

谢谢

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;

最佳答案

尝试作为

if (rs! = null) { 
while (rs.next()) {
returnValue = rs.getString("display_name");
}
......

关于java.sql.SQLException : Exhausted Resultset error 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23219733/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com