2010-09-15 18 views
2
ResultSet rs; 
    rs = this.orderedProduct.select(" sum(unitstoproduce) "," soNo = "+ soNo); 

    int sum = Integer.parseInt(rs.getString(1)); 

當我嘗試執行Java類中上面的查詢我收到例外如下。 這裏orderedProduct(orderedZnAlProduct)是表的SQLException:在結果的開始時設置

SELECT sum(unitstoproduce) FROM orderedZnAlProduct WHERE soNo = '15005' 

    java.sql.SQLException: Before start of result set 
+0

[ResultSet異常 - 在結果集開始之前]可能的重複(https://stackoverflow.com/questions/2120255/resultset-exception-before-start-of-result-set) – 2018-01-14 10:32:49

回答

11

我沒有看到執行查詢(如Statement.executeQuery的()),但是,這種錯誤的,當你的光標是不是很好地定位一般發生。你需要調用像rs.next()rs.first()這樣的移動你的光標,然後得到結果。

1

即使我遇到了同樣的問題,當我試圖執行

select count(*) TABLE_NAME 

但檢索值時,我從來沒有遇到過的錯誤在任何其他情況下,所以我假定這隻有一個行,那麼我們需要查詢明確提及rs.first(),它會像魅力一樣工作。

+0

Dafuuu ... SQL/JDBC可能真的是一個痛苦,有時候只是花了兩個小時的時間來調試直到找到這個線程。 – DragonGamer 2015-10-06 03:38:06