コード例 #1
0
  //	Add product into show_room_products table
  public void prodCollect(
      String prodName,
      String prodCode,
      String barCode,
      String brandName,
      double purchaseRate,
      double sellingRate,
      int quantity) {

    try {
      conn = dbAccess.connectToDataBase();
      stmt = conn.createStatement();

      //	insert product detail in show_room_products table
      sql =
          dbAccess.insertToCurrentStock(
              show_room_products,
              prodName,
              prodCode,
              barCode,
              brandName,
              purchaseRate,
              sellingRate,
              quantity);
      stmt.executeUpdate(sql);

      JOptionPane.showMessageDialog(null, "Product detail has been added to ShowRoom");

    } catch (Exception e) {
      // Handle errors for Class.forName
      e.printStackTrace();
    } finally {
      // finally block used to close resources
      try {
        if (stmt != null) {
          conn.close();
        }
      } catch (SQLException se) {
      }
      try {
        if (conn != null) {
          conn.close();
        }
      } catch (SQLException se) {
        se.printStackTrace();
      }
    } // end finally try
  }