closeConnection();
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException  {    Integer userId; // item id    Integer itemId; // user id    //     float   minBuyNow; // minimum acceptable BuyNow for this item    //     float   BuyNow;    // user BuyNow    //     float   maxBuyNow; // maximum BuyNow the user wants    int     maxQty; // maximum quantity available for this item    int     qty;    // quantity asked by the user    sp = new ServletPrinter(response, "StoreBuyNow");    /* Get and check all parameters */    String value = request.getParameter("userId");    if ((value == null) || (value.equals("")))    {      printError("<h3>You must provide a user identifier !<br></h3>");      return ;    }    else      userId = new Integer(value);    value = request.getParameter("itemId");    if ((value == null) || (value.equals("")))    {      printError("<h3>You must provide an item identifier !<br></h3>");      return ;    }    else      itemId = new Integer(value);    value = request.getParameter("maxQty");    if ((value == null) || (value.equals("")))    {      printError("<h3>You must provide a maximum quantity !<br></h3>");      return ;    }    else    {      Integer foo = new Integer(value);      maxQty = foo.intValue();    }    value = request.getParameter("qty");    if ((value == null) || (value.equals("")))    {      printError("<h3>You must provide a quantity !<br></h3>");      return ;    }    else    {      Integer foo = new Integer(value);      qty = foo.intValue();    }    /* Check for invalid values */    if (qty > maxQty)    {      printError("<h3>You cannot request "+qty+" items because only "+maxQty+" are proposed !<br></h3>");      return ;    }      String now = TimeManagement.currentDateToString();    // Try to find the Item corresponding to the Item ID    try     {      int quantity;      conn = getConnection();      conn.setAutoCommit(false);      stmt = conn.prepareStatement("SELECT quantity, end_date FROM items WHERE id=?");      stmt.setInt(1, itemId.intValue());      ResultSet irs = stmt.executeQuery();      if (!irs.first())      {        printError("This item does not exist in the database.");        return;      }      quantity = irs.getInt("quantity");      quantity = quantity -qty;      if (quantity == 0)      {        stmt = conn.prepareStatement("UPDATE items SET end_date=?, quantity=? WHERE id=?");        stmt.setString(1, now);        stmt.setInt(2, quantity);        stmt.setInt(3, itemId.intValue());        stmt.executeUpdate();      }      else      {        stmt = conn.prepareStatement("UPDATE items SET quantity=? WHERE id=?");        stmt.setInt(1, quantity);        stmt.setInt(2, itemId.intValue());        stmt.executeUpdate();      }    }    catch (SQLException e)    {      sp.printHTML("Failed to execute Query for the item: " +e+"<br>");      try      {        conn.rollback();      }      catch (Exception se)       {        printError("Transaction rollback failed: " + e);      }      return;    }    try     {	      stmt = conn.prepareStatement("INSERT INTO buy_now VALUES (NULL, \""+userId+                                   "\", \""+itemId+"\", \""+qty+"\", \""+now+"\")");      stmt.executeUpdate();      conn.commit();      sp.printHTMLheader("RUBiS: BuyNow result");      if (qty == 1)        sp.printHTML("<center><h2>Your have successfully bought this item.</h2></center>\n");      else        sp.printHTML("<center><h2>Your have successfully bought these items.</h2></center>\n");    }    catch (Exception e)    {      sp.printHTML("Error while storing the BuyNow (got exception: " +e+")<br>");      try      {        conn.rollback();      }      catch (Exception se)       {        printError("Transaction rollback failed: " + e +"<br>");      }      return ;    }		closeConnection();    sp.printHTMLfooter();  }