cartitem.java~18~
来自「本软件简单的实现的对商店的管理」· JAVA~18~ 代码 · 共 88 行
JAVA~18~
88 行
package eshop;import java.sql.*;public class CartItem { private int productID; private String productName; private double price; private String description; private int quantity; public void CartItem() { price=0; quantity=0; productName=""; description=""; } public boolean setItem(int productID,Connection conn){ this.productID=productID; boolean flag=true; try{ Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String sql = "SELECT * FROM PRODUCTS WHERE ProductID=" + productID; ResultSet rsProducts = stmt.executeQuery(sql); if(rsProducts.next()){ price=rsProducts.getDouble("Price"); productName=rsProducts.getString("ProductName"); description=rsProducts.getString("description"); }else{ flag=false; rsProducts.close(); stmt.close(); } } catch(Exception e){ e.printStackTrace(); flag=false; } return flag; } public void setPrice(double price){ this.price=price; } public void setName(String productName){ this.productName=productName; } public void setQuantity(int quantity){ this.quantity=quantity; } public int getProductID(){ return productID; } public double getPrice(){ return price; } public String getProductName(){ return productName; } public String getDescription(){ return description; } public int getQuantity(){ return quantity; } public void insert(int orderID,Connection conn){ if(quantity>0){ try{ Statement stmt=conn.createStatement(); sql="INSERT INTO OrderDetails(OrderID,ProductID,Price,Quantity)VALUES("+orderID+","+productID+","+price+","+quantity+")" } catch(Exception e){ e.printStackTrace(); } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?