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

📄 customer.java

📁 这个一个餐厅预定系统,可实现查询目前餐厅预订情况,实现餐桌预订以及就餐时为顾客调节餐桌的情况.
💻 JAVA
字号:
package bookingsystem;

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

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Customer {


    private int cno;
    private String cname;
    private String phone;
    Connection cn = ConnectionDB.getCon();
    Statement st = null;
    ResultSet rs = null;


     Customer(int cno)
    {
        try {
            existCustomerByCno(cno);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public Customer(String name,String phone) throws SQLException {
        this.cname = name;
        this.phone = phone;
        ResultSet rs1 = existCustomerByCname();
        if(rs==null)
        {
            addNewCustomer();
            existCustomerByCname();
        }

    }

    public ResultSet existCustomerByCname() throws SQLException {
        ResultSet rs0 = null;
        String sql = "select CNO,CNAME,PHONE" +" "+
        "FROM CUSTOMER where CNAME = '" + this.cname +"' AND PHONE = '"+this.phone+"'"  ;
        st =cn.createStatement();
        rs0 = st.executeQuery(sql);
        while(rs0.next())
        {
            this.cno = rs0.getInt("CNO");
        }
        return rs0;

    }

    public ResultSet existCustomerByCno(int cno) throws SQLException {
        String sql = "select CNO,CNAME,PHONE" +" "+
        "FROM CUSTOMER where CNO = " + cno ;
        st =cn.createStatement();
        rs = st.executeQuery(sql);
        while(rs.next())
        {
            this.cno = rs.getInt("CNO");
            this.cname = rs.getString("CNAME");
            this.phone = rs.getString("phone");
        }
        return rs;

    }

    public void addNewCustomer() throws SQLException {
        String insertSql = "INSERT INTO CUSTOMER (CNAME,PHONE) VALUES ('"+this.cname+"','"+this.phone+"')";
        PreparedStatement ps = cn.prepareStatement(insertSql);
        ps.executeUpdate();


    }

    public int getCno()
    {
        return this.cno;
    }
    public String getcname()
    {
        return cname;
    }
    public String getphone()
    {
       return phone;
    }

    public void setname(String name)
    {
        this.cname = cname;
    }
    public void setphone(String phone)
    {
        this.phone = phone;
    }
}

⌨️ 快捷键说明

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