当前位置:文档之家› 客户信息管理系统(说明文档)

客户信息管理系统(说明文档)

客户信息管理一、客户类package com.my.bean;//客户类public class Customer {private int id;private String customName;private String customPassword;private int age;private String address;private String phone;private String email;public String getCustomName() {return customName;}public void setCustomName(String customName) {this.customName = customName;}public String getCustomPassword() {return customPassword;}public void setCustomPassword(String customPassword) { this.customPassword = customPassword;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}@Overridepublic String toString() {// TODO Auto-generated method stubr eturn this.id+"\t"+this.customName+"\t"+this.customPassword+"\t"+this.age+"\t"+this.address+"\t"+this.phone+"\t"+this.email; }}二、数据库连接类package com.my.db;import java.sql.*;//数据库连接类public class DBCon {private Connection con;public Connection getConnection(){//方法一:JDBC-ODBC桥接/*try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载注册数据库驱动con=DriverManager.getConnection("jdbc:odbc:db","sa","sa");//建立连接} catch (SQLException ex) {System.out.println("数据库连接不成功!");ex.printStackTrace();} catch (ClassNotFoundException ex) {System.out.println("驱动找不到!");ex.printStackTrace();}*///方法二:纯粹的JAVA驱动try {Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//加载注册数据库驱动con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost :1433;databaseName=db","sa","sa");//建立连接} catch (SQLException ex) {System.out.println("数据库连接不成功!");ex.printStackTrace();} catch (ClassNotFoundException ex) {System.out.println("驱动找不到!");ex.printStackTrace();}return con;}}三、客户信息处理接口package com.my.dao;import java.util.List;import com.my.bean.Customer;//客房信息处理接口public interface CustomerDAO {public boolean addCustomerInfo(Customer c);//添加客户信息public boolean deleteCustomerInfo(int id);//根据编号删除客户信息public boolean modifyCustomerInfo(int id,Customer c);//根据编号修改客户信息public Customer getCustomer(int id);//根据编号查询客户信息public List getCustomer(String name);//根据姓名查询客户信息public List selectAll();//查询所有客户信息}四、客户信息处理业务类package com.my.impl;import java.sql.*;import java.util.*;import com.my.bean.Customer;import com.my.dao.CustomerDAO;import com.my.db.DBCon;public class CustomerInfoImpl implements CustomerDAO{private Connection con;private Statement st;private PreparedStatement pstmt;private ResultSet rs;private DBCon db;public CustomerInfoImpl() {db=new DBCon();}。

//实现接口中的方法,见下列代码1、添加客户信息//添加客户信息public boolean addCustomerInfo(Customer c){boolean result=false;con=db.getConnection();String sql="insert into customer values(?,?,?,?,?,?)";try {pstmt=con.prepareStatement(sql);pstmt.setString(1, c.getCustomName());pstmt.setString(2, c.getCustomPassword());pstmt.setInt(3, c.getAge());pstmt.setString(4, c.getAddress());pstmt.setString(5, c.getPhone());pstmt.setString(6, c.getEmail());int i=pstmt.executeUpdate();if(i>0){result=true;}else{result=false;}if (pstmt != null)pstmt.close();if (con != null)con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return result;}2、删除客户信息//删除客户信息public boolean deleteCustomerInfo(int id){boolean result=false;con=db.getConnection();String sql="delete from customer where id=?";try {pstmt=con.prepareStatement(sql);pstmt.setInt(1, id);int i=pstmt.executeUpdate();if(i>0){result=true;}else{result=false;}if (pstmt != null)pstmt.close();if (con != null)con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return result;}3、根据客户编号查询客户信息//根据客户编号查询客户信息public Customer getCustomerInfo(int id){Customer c=new Customer();con=db.getConnection();String sql="select * from customer where id=?";try {pstmt=con.prepareStatement(sql);pstmt.setInt(1, id);rs=pstmt.executeQuery();while (rs.next()) {c.setId(rs.getInt(1));c.setCustomName(rs.getString(2));c.setCustomPassword(rs.getString(3));c.setAge(rs.getInt(4));c.setAddress(rs.getString(5));c.setPhone(rs.getString(6));c.setEmail(rs.getString(7));}if(rs!=null)rs.close();if(pstmt!=null)pstmt.close();if(con!=null)con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return c;}4、根据客户姓名查询客户信息public List getCustomer(String name) {List list=new ArrayList();con=db.getConnection();String sql="select * from customer where customName=?";try {pstmt=con.prepareStatement(sql);pstmt.setString(1, name);rs=pstmt.executeQuery();while(rs.next()){Customer c=new Customer();c.setId(rs.getInt(1));c.setCustomName(rs.getString(2));c.setCustomPassword(rs.getString(3));c.setAge(rs.getInt(4));c.setAddress(rs.getString(5));c.setPhone(rs.getString(6));c.setEmail(rs.getString(7));list.add(c);}if(rs!=null) rs.close();if(pstmt!=null) pstmt.close();if(con!=null) con.close();} catch (SQLException ex) {Logger.getLogger(CustomerInfoImp.class.getName()).log(Level.SEVERE, null, ex);}return list;}5、根据客户编号修改客户信息//根据编号修改客户信息public boolean modifyCustomerInfo(int id,Customer c){boolean result=false;con=db.getConnection();String sql="update customer set customName=?,customPassword=?," +"age=?,address=?,phone=?,email=? where id=?";try {pstmt=con.prepareStatement(sql);pstmt.setString(1, c.getCustomName());pstmt.setString(2, c.getCustomPassword());pstmt.setInt(3, c.getAge());pstmt.setString(4, c.getAddress());pstmt.setString(5, c.getPhone());pstmt.setString(6, c.getEmail());pstmt.setInt(7, id);int i=pstmt.executeUpdate();if(i>0){result=true;}else{result=false;}if (pstmt != null)pstmt.close();if (con != null)con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return result;}6、查询所有客户信息//查询所有客户信息public List selectAll(){List list=new ArrayList();con=db.getConnection();String sql="select * from customer";try {st=con.createStatement();rs=st.executeQuery(sql);while(rs.next()){Customer c=new Customer();c.setId(rs.getInt(1));c.setCustomName(rs.getString(2));c.setCustomPassword(rs.getString(3));c.setAge(rs.getInt(4));c.setAddress(rs.getString(5));c.setPhone(rs.getString(6));c.setEmail(rs.getString(7));list.add(c);}if (rs != null)rs.close();if (pstmt != null)pstmt.close();if (con != null)con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list;}五、图形界面1、用户登录源代码:Login.javapublic class Login extends javax.swing.JFrame {private Connection con;private PreparedStatement pstmt;private DBCon db=new DBCon();private ResultSet rs;/*** Creates new form Login*/public Login() {initComponents();}。

相关主题