title: The DataBase is Locked..inserting values in table using a Loop
body: <p>I am making a restaurant management application in java using sqlite database. In application when order confirm button is pressed the application is supposed to insert into order table, insert into order dishes/Items and minuses the quantity of each ingredient used in dish that is added in an order..
  When i tried following code it says "SQLExcption:The Database is Locked "</p>
  
  <pre><code>for (int i = 0; i &lt; 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();
              }
          }
  </code></pre>
  
  <p>I think exception comes in while loop before updating ingriedients table but i don,t know why..plz suggest some solution..</p>