2010-09-29 23 views
0

我試圖獲得結果的類型和名稱,並在循環中輸入時,resumeset.next從true更改爲false ,並給出錯誤java.sql.SqlExcepcion用盡的結果集。有任何想法嗎?我真的不知道如何解決它,因爲我讀這個問題的解決方案後,並驗證結果集是否爲null之前開始循環。我把這種方法稱爲石英調度器。我在J2EE aplication利用這一點,並例子正是這種用盡resultset錯誤,當我得到列的名稱

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(); 
    } 
+0

你在哪裏捕捉這個異常?導致此異常的行在哪裏?您顯示的代碼不訪問結果集併吞下所有異常,並會產生不同的異常。 – BalusC 2010-09-29 02:16:55

+0

嗨,感謝您提出我的問題,我正在捕捉異常行中的'columnStatusType = metadata.getColumnType(i + 1);'在for循環的第二個 – Jorge 2010-09-29 19:13:09

回答

0

最後,我看到問題,而我在表達式視圖中用ecplise調試代碼時,我添加了下面的表達式res.next(),然後我爲該步驟傳遞的每個句子都帶來了評估表達式的結果如果結果集有更多行,則再次進行評估。在某些情況下,結果集已經評估了我在調試過程中所做的每個步驟的所有行。我唯一需要做的就是消除表達,並且工作正常...

1

變量columnlength似乎持有超過該查詢返回的列數的值。嘗試使用較小的色譜柱長度。

0

問題可能不在於代碼,而可能是數據庫。仔細檢查表格不是空的。如果表格爲空,則會出現此錯誤。請記住,像Oracle這樣的數據庫在所有插入,更新和更改語句之後都需要提交。在數據庫之外,您的更改可能不可見,除非您對數據庫運行了一次提交,但我長期存在此問題。我一直在用select語句檢查表,但是我的oracle數據庫的問題是我沒有發佈對數據庫的提交。

相關問題