我試圖在特定數量的查詢后獲得結果,即String sql="Select from mytable where sell_id = '"+purchase_id+"'"; java.sql.Statement stmt=conn.createStatement(); java.sql.ResultSet res=stmt.executeQuery(sql); while(res > 4){ //this line is where i still couldn't figured out String quantity = res.getString("quantity"); String item = res.getString("item_name"); String price = res.getString("price"); }但它顯示錯誤“二元運算符'>'的錯誤操作數類型”| quantity | item | price || 20 | soda | 5$ || 10 | noodle | 7$ || 5 | water | 3$ || 15 | gum | 4$ || 14 | tissue | 2$ | | 2 | snack | 6$ |結果應該是這樣的| 14 | tissue | 2$ | | 2 | snack | 6$ |任何建議都會被接受
3 回答
江戶川亂折騰
TA貢獻1851條經驗 獲得超5個贊
您可以使用一個計數器來檢查條件,如下所示:
int counter=1;
while(res.next()){
if(counter>4){
String quantity = res.getString("quantity");
String item = res.getString("item_name");
String price = res.getString("price");
}
counter++;
}
胡子哥哥
TA貢獻1825條經驗 獲得超6個贊
您的變量res不是數字。您實際上是在將對象與數字文字進行比較,因此您會收到錯誤消息。如果你想循環到你的結果集,你可以這樣做:
while(res.next()){
// do something here with your data
}
添加回答
舉報
0/150
提交
取消
