当我得到列的名称时,耗尽的结果集错误

时间:2010-09-29 02:12:02

标签: java jdbc

我正在尝试获取结果的类型和名称,当进入循环时,将相关元素的somo指令解释为resulset.next从true更改为false,并将错误java.sql.SqlExcepcion用尽结果集。有任何想法吗?我真的不知道如何解决它,因为我阅读了这个问题的解决方案的帖子,并验证结果集是否在开始循环之前为null。我用石英调度程序称这个方法。我在j2ee aplication中使用它,这个例子就是这个

try 
    {
        InitialContext ctx = new InitialContext(); 
        WrapperDataSource wrapperDataSource = (WrapperDataSource)ctx.lookup(systemLogger.getConfigurationParameters().getDataSource());
        conn = wrapperDataSource.getConnection();

        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
        conn = DriverManager.getConnection(url,login,password);

        if (conn != null)
        {
             stmt = conn.createStatement();
             res = stmt.executeQuery(query);

             if (res != null)
             {
                 while (res.next())
                {
                    for (int i = 0; i < columnlength; i++) 
                    {
                        String columnName = metadata.getColumnName(i+1);
                        if (metadata.getColumnName(i+1).equalsIgnoreCase(systemLogger.getColumnStatus())) 
                        {
                            columnStatusType = metadata.getColumnType(i+1);
                        }
                        else if (metadata.getColumnName(i+1).equalsIgnoreCase(systemLogger.getColumnDocumentId()))
                        {
                            columnDocumentIdType =  metadata.getColumnType(i+1);
                        }
                        else if (metadata.getColumnName(i+1).equalsIgnoreCase(systemLogger.getColumnTimer()))
                        {
                            columnTimerType =  metadata.getColumnType(i+1);
                        }
                    }
                }
             }
             else
             {
                __log.error("No results found for the query");
                throw new PtmServiceException("No se encontraron resultados para el query");
             }

        }
        else
        {
            __log.error("Could not create the connection");
            throw new PtmServiceException("No se pudo crear la conexion");
        }

    } 
    catch(Exception e)
    {
        __log.error("Error in the execution of the query");
        throw new PtmServiceException("Error ejecutando la busqueda");
    }
    finally
    {
        res.close();
        stmt.close();
        conn.close();
    }

3 个答案:

答案 0 :(得分:1)

变量columnlength似乎保持一个大于查询返回的列数的值。尝试使用较小的柱长。

答案 1 :(得分:0)

最后,我看到了问题,当我在表达式的视图中使用ecplise调试代码时我添加了以下表达式res.next(),然后我为该步骤传递的每个句子带来的结果是表达式,用于评估结果集是否包含更多行,再次进行评估。在某些时候,结果集已经评估了我在调试过程中所做的每一步的所有行。我唯一需要做的就是消除表达并正常工作......

答案 2 :(得分:0)

问题可能不在于代码,而是可能是数据库。仔细检查TABLE是否为空。如果表为空,则会出现此错误。请记住,像Oracle这样的数据库需要在所有insert,update,alter语句之后提交。在数据库之外可能看不到您的更改,直到您对数据库运行提交,我遇到了这个问题很长一段时间。我继续用select语句检查表,但是我的oracle db的问题是我没有对我的数据库发出提交。