2016-02-12 34 views
-2

我試圖執行此代碼時出現錯誤。java.sql.SQLException:jdbc錯誤中的用盡結果集

我的要求是使用getInt()將字符串轉換爲數據庫。

for (int i = 1; i <= 7; i++) { 
    int t = rs.getInt(i); 

    temp = Integer.toString(t); 
    if (temp.length() == 1) temp="00"+temp; 
    else if (temp.length() == 2) temp="0"+temp; 
    else temp=temp; 
    output=output+temp; 
     ... 

Error

回答

0

好像你的結果集少於七行,讓你在for循環跑了出來。檢查rs.hasNext()以查看是否還有其他行要處理是個好主意。

0

你沒有表現出相應的代碼(但它的屏幕截圖是可見的),這是while環路for循環包括你前面:

while (rs.next()) { 
    blah blah blah 
} 

這個循環從SQL讀取所有行select聲明,使ResultSet完全消耗(又稱耗盡)。

當你rs.next()回到false然後rs.getInt(i)之後,你被告知,「對不起,沒有做不到的,你已經使用的所有數據」,又名SQLException: Exhausted Resultset