开发者

exhausted resultset error when i get the name of the columns

i'm trying to get the type and the name of the result and when enter in the loop, excuting somo instructions about the metadata the resulset.next changed from true to false, and give the error java.sql.SqlExcepcion exhausted resultset. Any ideas? i really dont know how solved it because i read the post with the solution of this problem and validate if the resultset it's null before begin the loop. I'm called this method with a scheduler of quartz. I'm using this in a j2ee aplication and the example it's this

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);
                      开发者_Go百科  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();
    }


The variable columnlength seems to hold a value larger than the number of columns returned by the query. Try with a smaller columnlength.


finally, i see the problem, while i'm debugging the code with ecplise in the view of the expressions i added the follow expression res.next(), then each sentence that i pass for the step into bring the consequence that expression that evaluate if the resultset has more rows, be evaluated again. In some point the resultset has evaluated all the rows for each step into that i made in the process of debugging. The only thing that i have to do was eliminate the expression and works fine...


The problem might not be with the code but instead could be the database. Double check that the TABLE IS NOT EMPTY. You get this error if the table is empty. Keep in mind that databases like Oracle require a commit after all your insert, update, alter statements .Your changes might not be visible outside the database till you run a commit over the your db, I was having this problem for quite a long time. I kept on checking the table with select statement but the problem with my oracle db was that I had not issued a commit over my db.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜