Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.sql.SQLException:使用select语句时耗尽了Resultset_Java_Sql_Jdbc - Fatal编程技术网

java.sql.SQLException:使用select语句时耗尽了Resultset

java.sql.SQLException:使用select语句时耗尽了Resultset,java,sql,jdbc,Java,Sql,Jdbc,我有下面一段代码,在其中我试图创建用户id的广告jdoe、jdoe1、jdoe2等等。 我正在为其检查唯一性(或根据sql表检查用户id是否存在)。我不断地被结果集错误弄得精疲力竭。我理解这是因为select查询没有找到“jdoe”(这很好),但我无法处理它 PreparedStatement pstmt = conn.prepareStatement("SELECT DISTINCT name FROM t_av_accounts WHERE name = ? "); ResultSe

我有下面一段代码,在其中我试图创建用户id的广告jdoe、jdoe1、jdoe2等等。 我正在为其检查唯一性(或根据sql表检查用户id是否存在)。我不断地被结果集错误弄得精疲力竭。我理解这是因为select查询没有找到“jdoe”(这很好),但我无法处理它

PreparedStatement pstmt = conn.prepareStatement("SELECT DISTINCT name FROM t_av_accounts WHERE name = ? ");
    ResultSet rs = null;

/*Some more code here*/

ret = builder.toString();
        log.debug("** Start SUFFIX: " + suffix.toString() + "&& ret: " + ret);
        while(x){
            pstmt.setString(1, ret);
            rs = pstmt.executeQuery();
            if(rs != null){
                rs.next();
                if(rs.getString(1) == ret){
                    if(suffix==1)
                        ret.concat(suffix.toString());
                    else
                        ret.substring(ret.length()-1).concat(suffix.toString());
                ++suffix;
                log.debug("** Current SUFFIX: " + suffix.toString() + "&& ret: " + ret);
                }
                else{
                    ctx.setUserVariable(WorkflowContext.VariableLevel.Job, "AFXUSERCUSTOM_"+user.getId()+"_CUSTOM_USERID", ret.toLowerCase());
                    x = false;
                }
            }
        }

您可以检测到,在执行任何导致引发异常的操作之前,您的查询没有返回任何行。报告说:

当对下一个方法的调用返回false时,光标位于最后一行之后。任何需要当前行的ResultSet方法调用都将导致抛出SQLException


当前,您的代码正在丢弃由
rs返回的值。下一步,让您的代码检查返回值。如果为false,则不会返回任何行,您可以避免调用
rs.getString(1)

我更改了while循环:

while(x){
            pstmt.setString(1, ret);
            rs = pstmt.executeQuery();
            if(!rs.next()){
                ctx.setUserVariable(WorkflowContext.VariableLevel.Job, "AFXUSERCUSTOM_"+user.getId()+"_CUSTOM_USERID", ret);
                x = false;
            }
            else{
                rsName = rs.getString(1);
                if(suffix==1)
                    ret = ret.concat(suffix.toString());
                else
                    ret = (ret.substring(0,ret.length()-1)) + suffix.toString();
                ++suffix;
                log.error("** Current SUFFIX: " + suffix.toString() + " && ret: " + ret + " && rsName that found: " + rsName);
            }
        }