我使用sqlite數據庫在java中製作餐廳管理應用程序。在申請確認按鈕時按下應用程序應該插入到訂單表中,插入訂單菜單/項目和用於添加的菜餚中所用的每種配料的數量.. 當我試着下面的代碼它說「SQLExcption:該數據庫被鎖定」數據庫被鎖定..使用循環插入表中的值
for (int i = 0; i < orderTable.getRowCount(); i++) {
pst = con.prepareStatement("select dishId from dishes where dishName = '" + orderTable.getValueAt(i, 1) + "'");
rs = pst.executeQuery();
int dishId = rs.getInt("dishId");
pst = con.prepareStatement("insert into orderDishes values(?,?,?)");
pst.setInt(1, currentOrderNumber);
pst.setInt(2, dishId);
pst.setInt(3, (int) orderTable.getValueAt(i, 0));
pst.executeUpdate();
pst = con.prepareStatement("select ingId , quantity from dishIng where dishId = '" + dishId + "'");
rs = pst.executeQuery();
while (rs.next()) {
ingReducedQuantity = rs.getInt("quantity");
ingId = rs.getInt("ingId");
pst1 = con1.prepareStatement("select qunatity from ingriedients where ingId = '" + ingId + "'");
rs1 = pst1.executeQuery();
previousQuantity = rs1.getInt("qunatity");
pst1.close();
rs1.close();
con1.commit();
newQuantity = previousQuantity - ingReducedQuantity;
// Here it gives exception
pst1 = con1.prepareStatement("update ingriedients set qunatity = '" + newQuantity + "' where ingId = '" + ingId + "'");
pst1.executeUpdate();
con1.commit();
}
}
我覺得異常進來,同時更新ingriedients表,但我不前循環,知道why..plz提出了一些解決辦法..
你有這樣的錯字:從...選擇qunatity你也拼寫'成分',但你一直這樣做,所以也許這不是問題。 – 2014-12-07 05:40:49
其實列名是qunatity所以它不是一個錯字..也沒有語法錯誤它是某種連接問題.. – 2014-12-07 05:47:07