⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 order.java

📁 用java+Ajax做的图书商城
💻 JAVA
字号:
package shoppcart;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;


public class Order {
    private String productID;
    private int productCount;
    private String ownerId;
    public String getOwnerID(){
        return this.ownerId;
    }
    public void setOwnerID(String ownerID){
        this.ownerId=ownerID;
    }
    public String getProductID(){
        return this.productID;
    }
    public void setProductID(String ProductID){
        this.productID=ProductID;
    }
    public int getProductCount(){
        return this.productCount;
    }
    public void setProductCount(int count){
        this.productCount=count;
    }    
    public Order() {  }
    public void serial(){
        ConnectManager manager=null;
        Connection con=null;
        PreparedStatement stamt=null;
        try {
            manager=new ConnectManager();
            con=manager.getConnection();
            stamt=con.prepareStatement("insert into orders(ownerId,productId,productCount)" +
                    " values(?,?,?)");
            stamt.setString(1,this.getOwnerID());
            stamt.setString(2,this.getProductID());
            stamt.setInt(3,this.getProductCount());
            stamt.executeUpdate();
        }
        catch(SQLException e){
            e.printStackTrace();
        }
        finally{
            if(stamt!=null){
                try{
                    stamt.close();
                }catch(SQLException e){
                    e.printStackTrace();
                }
            }
            if(con!=null){
                try{
                    con.close();
                }catch(SQLException e){
                    e.printStackTrace();
                }
            }
            if(manager!=null){
                manager.close();
            }
        }
    }
    public static List<Order> getOrderList(String ownerID){
        ConnectManager manager=null;
        Connection con=null;
        PreparedStatement stamt=null;
        ArrayList<Order> orderList=new ArrayList<Order>();
        try {
            manager=new ConnectManager();
            con=manager.getConnection();
            stamt=con.prepareStatement("select * from orders where ownerId=?");
            stamt.setString(1,ownerID);
            ResultSet rs=stamt.executeQuery();
            while(rs.next()){
                Order order=new Order();
                order.setOwnerID(rs.getString("ownerId"));
                order.setProductID(rs.getString("productId"));
                order.setProductCount(rs.getInt("productCount"));
                orderList.add(order);
            }
            return orderList;
        }
        catch(SQLException e){
            e.printStackTrace();
            return null;
        }
        finally{
            if(stamt!=null){
                try{
                    stamt.close();
                }catch(SQLException e){
                    e.printStackTrace();
                }
            }
            if(con!=null){
                try{
                    con.close();
                }catch(SQLException e){
                    e.printStackTrace();
                }
            }
            if(manager!=null){
                manager.close();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -