Java超市管理系统

代码:

package view;

import javax.swing.*;

import org.jvnet.substance.skin.*;

import bean.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import service.*;

/**
 * 在需要使用事件的窗体类中 实现事件接口 在需要使用事件的控件上添加注册事件
 *
 * @author Administrator
 *
 */
public class FirstFrame extends JFrame implements ActionListener {
 // 类的成员<=>窗体上面的控件 control<=>class
 private JButton jButton;
 private JButton jButton2;
 private JButton jButton3;
 private JLabel jLabel;
 private JLabel jLabel2;

 public FirstFrame() {

  this.setSize(600, 550);
  this.setTitle("用户登录窗体 ");
  this.setLocationRelativeTo(null);
  this.setLayout(null);// 空布局
  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  this.init();
  this.setVisible(true);// 最后

 }

 /**
  * 初始化窗体在其它成员
  */
 public void init() {
  // 实例化
  this.jLabel = new JLabel("职工入口处");
  this.jLabel.setBounds(163, 333, 120, 30);
  ImageIcon iic2 = new ImageIcon("images/超市门口.png");
  iic2.setImage(iic2.getImage().getScaledInstance(120, 90,
    Image.SCALE_DEFAULT));
  this.jButton = new JButton(iic2);
  // 设置坐标
  this.jButton.setBounds(133, 363, 120, 98);
  
  
  ImageIcon iic3 = new ImageIcon("images/后门.png");
  iic3.setImage(iic3.getImage().getScaledInstance(40, 40,
    Image.SCALE_DEFAULT));
  this.jButton2 = new JButton(iic3);
  // 设置坐标
  this.jButton2.setBounds(356, 403, 40, 40);
  
  
  ImageIcon iic4 = new ImageIcon("images/VIP图.jpg");
  iic4.setImage(iic4.getImage().getScaledInstance(50,100,
    Image.SCALE_DEFAULT));
  this.jButton3 = new JButton(iic4);
  // 设置坐标
  this.jButton3.setBounds(430, 350, 50, 100);

  // 添加控制到窗体

  ImageIcon iic = new ImageIcon("images/超市背景.jpg");
  iic.setImage(iic.getImage().getScaledInstance(600, 550,
    Image.SCALE_DEFAULT));
  // 为控件添加注册事件
  this.jLabel2 = new JLabel(iic);
  this.jLabel2.setBounds(0, 0, 600, 550);

  System.out.println(jLabel);
  this.jButton.setActionCommand("a");
  this.jButton2.setActionCommand("b");
  this.add(jButton);
  this.add(jButton2);
  this.add(jButton3);
  this.add(jLabel);
  this.add(jLabel2);
  
  this.jButton.addActionListener(this);// 接口做为参数,传实现了接口class
  this.jButton2.addActionListener(this);
 }

 @Override
 public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  if (e.getActionCommand().equals("a")) {
  LoginFrame loginFrame = new LoginFrame();
  this.dispose();
  }
  if (e.getActionCommand().equals("b")) {
   VipinfoFrame vipinfoFrame = new VipinfoFrame();
   this.dispose();
   }
 }

}

 


Java超市管理系统

窗体代码:

package view;

import javax.swing.*;

import org.jvnet.substance.skin.*;

import bean.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import service.*;

/**
 * 在需要使用事件的窗体类中 实现事件接口 在需要使用事件的控件上添加注册事件
 *
 * @author Administrator
 *
 */
public class LoginFrame extends JFrame implements ActionListener {
 // 类的成员<=>窗体上面的控件 control<=>class
 private JLabel jLabelback;
 private JButton jButton;
 private JTextField jTextField;
 private JTextField jTextField2;
 private JComboBox jComboBox;
 public LoginFrame() {
  
  this.setSize(600, 550);
  this.setTitle("用户登录窗体 ");
  this.setLocationRelativeTo(null);
  this.setLayout(null);// 空布局
  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  this.init();
  this.setVisible(true);// 最后
  
 }

 /**
  * 初始化窗体在其它成员
  */
 public void init() {
  // 实例化
  ImageIcon iic = new ImageIcon("images/登录.jpg");
  iic.setImage(iic.getImage().getScaledInstance(600, 550, Image.SCALE_DEFAULT));
  // 为控件添加注册事件
  this.jLabelback=new JLabel(iic);
  this.jLabelback.setBounds(0, 0, 600, 550);
  this.jTextField=new JTextField();
  this.jTextField2=new JTextField();
  this.jComboBox = new JComboBox();
  this.jComboBox.addItem("管理员");
  this.jComboBox.addItem("售货员");
  this.jComboBox.addItem("采购员");
  this.jButton=new JButton("登录");
  this.jButton.setBounds(200,346, 220, 41);
  this.jTextField.setBounds(270, 230, 145, 25);
  this.jTextField2.setBounds(270, 265, 145, 25);
  this.jComboBox.setBounds(270, 295, 140, 28);
  this.add(jComboBox);
  this.add(jButton);
  this.add(jTextField);
  this.add(jTextField2);
  this.add(jLabelback);
  this.jButton.addActionListener(this);
 }

 @Override
 public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  if (e.getActionCommand().equals("登录")) {
    // 收集完成数据
    String empname = this.jTextField.getText().trim();
    String emppwd =  this.jTextField2.getText().trim();
    String empjob = this.jComboBox.getSelectedItem().toString();// 不是null
    System.out.println(empname+" "+emppwd+" "+empjob);
    if (empname.equals("") || emppwd.equals("")) {
     JOptionPane.showMessageDialog(this, "你没有输入信息");
    } else if(empjob.equals("售货员")) {
     Empinfo empinfo = new Empinfo();
     empinfo.setEmpName(empname);
     empinfo.setEmpPwd(emppwd);
     empinfo.setEmpJob(empjob);
     // 调用

     EmpinfoServer empInfoService = new EmpinfoServer();

     try {
      Empinfo u = empInfoService.getEmpInfo(empinfo);
      if (u != null) {
       JOptionPane.showMessageDialog(this, "成功");
       OutputFrame outputFrame = new OutputFrame();
       this.dispose();

      } else {
       JOptionPane.showMessageDialog(this, "失败");
      }
     } catch (Exception e1) {
      // TODO Auto-generated catch block
      // e1.printStackTrace();
      // ui
      JOptionPane.showMessageDialog(this, e1.getMessage());
     }
    }
    else if(empjob.equals("管理员")) {
     Empinfo empinfo = new Empinfo();
     empinfo.setEmpName(empname);
     empinfo.setEmpPwd(emppwd);
     empinfo.setEmpJob(empjob);
     // 调用

     EmpinfoServer empInfoService = new EmpinfoServer();

     try {
      Empinfo u = empInfoService.getEmpInfo(empinfo);
      if (u != null) {
       JOptionPane.showMessageDialog(this, "成功");
       EmpInfoManageFrame empInfoManageFrame = new EmpInfoManageFrame();
       this.dispose();

      } else {
       JOptionPane.showMessageDialog(this, "失败");
      }
     } catch (Exception e1) {
      // TODO Auto-generated catch block
      // e1.printStackTrace();
      // ui
      JOptionPane.showMessageDialog(this, e1.getMessage());
     }
    }
    else if(empjob.equals("采购员")) {
     Empinfo empinfo = new Empinfo();
     empinfo.setEmpName(empname);
     empinfo.setEmpPwd(emppwd);
     empinfo.setEmpJob(empjob);
     // 调用

     EmpinfoServer empInfoService = new EmpinfoServer();

     try {
      Empinfo u = empInfoService.getEmpInfo(empinfo);
      if (u != null) {
       JOptionPane.showMessageDialog(this, "成功");
       GoodsFrame goodsFrame = new GoodsFrame();
       this.dispose();

      } else {
       JOptionPane.showMessageDialog(this, "失败");
      }
     } catch (Exception e1) {
      // TODO Auto-generated catch block
      // e1.printStackTrace();
      // ui
      JOptionPane.showMessageDialog(this, e1.getMessage());
     }
    }
   }

  }

 }

 功能实现代码:

package bean;

public class Empinfo {
private int empid;
private String empName;
private String empSex;
private String empPwd;
private int empAge;
private String empAdd;
private String empTel;
private String empJob;
public String getEmpPwd() {
 return empPwd;
}
public void setEmpPwd(String empPwd) {
 this.empPwd = empPwd;
}
public int getEmpid() {
 return empid;
}
public void setEmpid(int empid) {
 this.empid = empid;
}
public String getEmpName() {
 return empName;
}
public void setEmpName(String empName) {
 this.empName = empName;
}
public String getEmpSex() {
 return empSex;
}
public void setEmpSex(String empSex) {
 this.empSex = empSex;
}
public int getEmpAge() {
 return empAge;
}
public void setEmpAge(int empAge) {
 this.empAge = empAge;
}
public String getEmpAdd() {
 return empAdd;
}
public void setEmpAdd(String empAdd) {
 this.empAdd = empAdd;
}
public String getEmpTel() {
 return empTel;
}
public void setEmpTel(String empTel) {
 this.empTel = empTel;
}
public String getEmpJob() {
 return empJob;
}
public void setEmpJob(String empJob) {
 this.empJob = empJob;
}
}

 

package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import db.DbUtil;
import bean.Empinfo;;

/**
 * userinfo表的数据操作类
 *
 * @author Administrator
 *
 */
public class EmpInfoDao {

 /**
  * 根据用户信息查找用户对象
  *
  * @param userinfo
  *            用户对象
  * @return Userinfo
  * @throws Exception
  */
 public int addEmpinfo(Empinfo empinfo) throws Exception {
  int count=0;
  try {
   String sql="insert into empinfo (empId,empName,empPwd,empSex,empAge,empAdd,empTel,empJob) values(?,?,?,?,?,?,?,?)";
   ArrayList<Object> paramrs=new ArrayList<Object>();
   paramrs.add(empinfo.getEmpid());
   paramrs.add(empinfo.getEmpName());
   paramrs.add(empinfo.getEmpPwd());
   paramrs.add(empinfo.getEmpSex());
   paramrs.add(empinfo.getEmpAge());
   paramrs.add(empinfo.getEmpAdd());
   paramrs.add(empinfo.getEmpTel());
   paramrs.add(empinfo.getEmpJob());
   count = DbUtil.executeUpdate(sql, paramrs);
   
   
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  return count;
  
 }
 
 public Empinfo getEmpinfo(Empinfo empinfo) throws Exception {
  System.out.println(empinfo.getEmpName()+"555");
  Empinfo u = null;
  // 动态查询
  // 1 关于变量默认值
  // 2 动态条件
  // 3 细节 大量处理字符窜拼接
  /*
   * String 3种场景 1 final String 字符窜常量池 <=>复用 常量 字符窜+变量 字符窜+字符窜 2
   * StringBuilder,StringBuffer(线程安全) 字符窜缓存 效率 3 String s=new String()
   * 字符工具类
   */
  StringBuffer sql = new StringBuffer(
    "select empid,empName,empPwd,empjob from empinfo where 1=1");
  ArrayList<Object> paramrs = new ArrayList<Object>();
  if (empinfo.getEmpid() != 0) {
   sql.append(" and empid=? ");
   // 设置参数
   paramrs.add(empinfo.getEmpid());
  }
  // null ""
  if (!empinfo.getEmpName().equals("")) {
   sql.append(" and empName=? ");
   paramrs.add(empinfo.getEmpName());
  }
  if (!empinfo.getEmpPwd().isEmpty()) {
   sql.append(" and empPwd=? ");
   paramrs.add(empinfo.getEmpPwd());
  }
  if (!empinfo.getEmpJob().isEmpty()) {
   sql.append(" and empjob=? ");
   paramrs.add(empinfo.getEmpJob());
  }
  
  ResultSet rs = DbUtil.executeQuery(sql.toString(), paramrs);
  System.out.println(sql.toString());
  try {
   while (rs.next()) {
    u = new Empinfo();
    u.setEmpid(rs.getInt("empid"));
    u.setEmpName(rs.getString("empName"));
    u.setEmpPwd(rs.getString("empPwd"));
    u.setEmpJob(rs.getString("empJob"));
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   // e.printStackTrace();
   // 方法的调用者 <=>Exception 项目 自定义异常类型
   throw new Exception("数据操作异常");
  }

  return u;

 }

 /**
  * 获取所有用户集合
  *
  * @return ArrayList<Userinfo>
  * @throws Exception
  */
 public int updateEmpinfo(Empinfo empinfo,Empinfo empinfo2)throws Exception {
  int count=0;
//  System.out.println("empinfo2:"+empinfo2.getEmpId());
  try {
   StringBuffer sql1=new StringBuffer("update empinfo set ");
   ArrayList<Object> paramrs=new ArrayList<Object>();
   
   if (empinfo.getEmpName()!=null) {
    sql1.append(" empName=? ,");
    paramrs.add(empinfo.getEmpName());
   }
   if (empinfo.getEmpPwd()!=null) {
    sql1.append(" empPwd=? ,");
    paramrs.add(empinfo.getEmpPwd());
   }
   if (empinfo.getEmpSex()!=null) {
    sql1.append(" empSex=? ,");
    paramrs.add(empinfo.getEmpSex());
   }
   if (empinfo.getEmpAge() != 0) {
    sql1.append(" empAge=? ,");
    
    paramrs.add(empinfo.getEmpAge());
   }
   if (empinfo.getEmpAdd()!=null) {
    sql1.append(" empAdd=? ,");
    paramrs.add(empinfo.getEmpAdd());
   }
   if (empinfo.getEmpTel()!=null) {
    sql1.append(" empTel=? ,");
    paramrs.add(empinfo.getEmpTel());
   }
   if (empinfo.getEmpJob()!=null) {
    sql1.append(" empJob=? ,");
    paramrs.add(empinfo.getEmpJob());
   }
   int index=sql1.lastIndexOf(",");
   sql1=sql1.deleteCharAt(index);
   StringBuffer sql=new StringBuffer("where 1=1 ");
   sql=sql1.append(sql);
   if (empinfo2.getEmpid() != 0) {
    sql.append(" and empId=? ");
    paramrs.add(empinfo2.getEmpid());
   }
   
//   System.out.println(sql.toString());
   count = DbUtil.executeUpdate(sql.toString(), paramrs); 
   
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  return count;
 }
 /**
  * 查
  */
 public ArrayList<Empinfo> selectEmpinfo(Empinfo empinfo)throws Exception {
  ArrayList<Empinfo> empinfos=new ArrayList<Empinfo>();
  try {
   StringBuffer sql=new StringBuffer("select empId,empName,empPwd,empSex,empAge,empAdd,empTel,empJob from empinfo where 1=1");
   ArrayList<Object> paramrs = new ArrayList<Object>();
   if (empinfo.getEmpid() != 0) {
    sql.append(" and empId=? ");
    // 设置参数
    paramrs.add(empinfo.getEmpid());
   }
//   System.out.println(empinfo.getEmpName());检测是何种空
   if (empinfo.getEmpName()!=null) {
    sql.append(" and empName=? ");
    paramrs.add(empinfo.getEmpName());
   }
   if (empinfo.getEmpPwd()!=null) {
    sql.append(" and empPwd=? ");
    paramrs.add(empinfo.getEmpPwd());
   }
   if (empinfo.getEmpSex()!=null) {
    sql.append(" and empSex=? ");
    paramrs.add(empinfo.getEmpSex());
   }
   if (empinfo.getEmpAge() != 0) {
    sql.append(" and empAge=? ");
    
    paramrs.add(empinfo.getEmpAge());
   }
   if (empinfo.getEmpAdd()!=null) {
    sql.append(" and empAdd=? ");
    paramrs.add(empinfo.getEmpAdd());
   }
   if (empinfo.getEmpTel()!=null) {
    sql.append(" and empTel=? ");
    paramrs.add(empinfo.getEmpTel());
   }
   if (empinfo.getEmpJob()!=null) {
    sql.append(" and empJob=? ");
    paramrs.add(empinfo.getEmpJob());
   }

//   System.out.println(sql.toString());
   ResultSet res = DbUtil.executeQuery(sql.toString(), paramrs);
   while(res.next()){
    Empinfo empinfo1=new Empinfo();
    empinfo1.setEmpid(res.getInt("empId"));
    empinfo1.setEmpName(res.getString("empName"));
    empinfo1.setEmpPwd(res.getString("empPwd"));
    empinfo1.setEmpSex(res.getString("empSex"));
    empinfo1.setEmpAge(res.getInt("empAge"));
    empinfo1.setEmpAdd(res.getString("empAdd"));
    empinfo1.setEmpTel(res.getString("empTel"));
    empinfo1.setEmpJob(res.getString("empJob"));
    empinfos.add(empinfo1);
   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  return empinfos;
  
 }
 /**
  * 查
  */
 public Empinfo selectEmpinfo2(Empinfo empinfo)throws Exception {
  Empinfo empinfos=null;
  try {
   StringBuffer sql=new StringBuffer("select empId,empName,empPwd,empSex,empAge,empAdd,empTel,empJob from empinfo where 1=1");
   ArrayList<Object> paramrs = new ArrayList<Object>();
   if (empinfo.getEmpid() != 0) {
    sql.append(" and empId=? ");
    // 设置参数
    paramrs.add(empinfo.getEmpid());
   }
   System.out.println(empinfo.getEmpid());
//   System.out.println(empinfo.getEmpName());检测是何种空
   if (empinfo.getEmpName()!=null) {
    sql.append(" and empName=? ");
    paramrs.add(empinfo.getEmpName());
   }
   if (empinfo.getEmpPwd()!=null) {
    sql.append(" and empPwd=? ");
    paramrs.add(empinfo.getEmpPwd());
   }
   if (empinfo.getEmpSex()!=null) {
    sql.append(" and empSex=? ");
    paramrs.add(empinfo.getEmpSex());
   }
   if (empinfo.getEmpAge() != 0) {
    sql.append(" and empAge=? ");
    
    paramrs.add(empinfo.getEmpAge());
   }
   if (empinfo.getEmpAdd()!=null) {
    sql.append(" and empAdd=? ");
    paramrs.add(empinfo.getEmpAdd());
   }
   if (empinfo.getEmpTel()!=null) {
    sql.append(" and empTel=? ");
    paramrs.add(empinfo.getEmpTel());
   }
   if (empinfo.getEmpJob()!=null) {
    sql.append(" and empJob=? ");
    paramrs.add(empinfo.getEmpJob());
   }

//   System.out.println(sql.toString());
   System.out.println("sql:"+sql+"params:"+paramrs);
   ResultSet res = DbUtil.executeQuery(sql.toString(), paramrs);
   while(res.next()){
    empinfos=new Empinfo();
    empinfos.setEmpid(res.getInt("empId"));
    empinfos.setEmpName(res.getString("empName"));
    empinfos.setEmpPwd(res.getString("empPwd"));
    empinfos.setEmpSex(res.getString("empSex"));
    empinfos.setEmpAge(res.getInt("empAge"));
    empinfos.setEmpAdd(res.getString("empAdd"));
    empinfos.setEmpTel(res.getString("empTel"));
    empinfos.setEmpJob(res.getString("empJob"));
    
    System.out.println("empinfos:"+empinfos+"empinfos:"+empinfos.getEmpName());
    break;
   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  return empinfos;
  
 }
 /**
  * 全部查询
  */
public ArrayList<Empinfo> selectAllEmpinfo()throws Exception {
 ArrayList<Empinfo> empinfos=new ArrayList<Empinfo>();
 
 try {
  String sql="select empId,empName,empPwd,empSex,empAge,empAdd,empTel,empJob from empinfo";
  ResultSet res=DbUtil.getResultSet(sql);
  while(res.next()){
   Empinfo empinfo=new Empinfo();
   empinfo.setEmpid(res.getInt("empId"));
   empinfo.setEmpName(res.getString("empName"));
   empinfo.setEmpPwd(res.getString("empPwd"));
   empinfo.setEmpSex(res.getString("empSex"));
   empinfo.setEmpAge(res.getInt("empAge"));
   empinfo.setEmpAdd(res.getString("empAdd"));
   empinfo.setEmpTel(res.getString("empTel"));
   empinfo.setEmpJob(res.getString("empJob"));
   empinfos.add(empinfo);

 

  }
 } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 return empinfos;
 

}
}

package db;

import java.util.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;

/**
 * java 操作数据库 工具类<=>代码重构<=>复用 jdbc
 *
 * @author Administrator
 *
 */
public class DbUtil {
 // JDBC 3三大对象(组件)
 // static 场景 生命周期:程序启动时,自动初始化,只会初始1次
 private static Connection con = null;// 连接对象
 private static PreparedStatement psmt = null;// 预编译命令对象
 private static ResultSet rs = null;// 结果集对象

 /**
  * 获取连接对象
  *
  * @return Connection
  */
 public static Connection getConnetion() {
  try {
   Properties properties = new Properties();
   properties.load(new FileInputStream("config.properties"));
   Class.forName(properties.getProperty("driverName"));
   con = DriverManager.getConnection(properties.getProperty("url"),
     properties.getProperty("user"),
     properties.getProperty("password"));
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  return con;
 }

 /**
  * 获取预编译命令对象
  *
  * @param sql
  *            语句
  * @return PreparedStatement
  */
 public static PreparedStatement getPreparedStatement(String sql) {
  con = getConnetion();
  try {
   psmt = con.prepareStatement(sql);
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  return psmt;
 }

 /**
  * 获取结果集对象
  *
  * @param sql
  *            语句
  * @return ResultSet
  */
 public static ResultSet getResultSet(String sql) {
  try {
   psmt = getPreparedStatement(sql);

   rs = psmt.executeQuery();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return rs;
 }

 // insert,update,delete
 // ? ? ? 参数个数 不统一 动态性 集合ArrayList<Object>
 // 参数的数据类型 不统一 Object
 // 思路

 /**
  * 执行sql语句返回受影响行数
  *
  * @param sql
  *            语句 支持insert,update,delete
  * @param paramrs
  *            参数集合列表
  * @return int
  */
 public static int executeUpdate(String sql, ArrayList<Object> paramrs) {
  int count = 0;
  try {
   getPreparedStatement(sql);
   // 设置参数
   for (int i = 0; i < paramrs.size(); i++) {
    // 1 参数下标 2 参数的数据类型
    // 细节 下标
    psmt.setObject(i + 1, paramrs.get(i));

   }
   // 执行
   count = psmt.executeUpdate();

  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
   // 关闭资源
   closeAll();

  }

  return count;
 }

 /**
  * 执行 sql语句返回结果集
  *
  * @param sql
  *            语句 支持 select
  * @param paramrs
  *            参数集合列表
  * @return ResultSet
  */
 public static ResultSet executeQuery(String sql, ArrayList<Object> paramrs) {
  getPreparedStatement(sql);
  try {
   // 细节
   if (paramrs != null) {
    // 设置参数
    // 设置参数
    for (int i = 0; i < paramrs.size(); i++) {
     // 1 参数下标 2 参数的数据类型
     // 细节 下标
     psmt.setObject(i + 1, paramrs.get(i));

    }
   }

   rs = psmt.executeQuery();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  return rs;

 }

 //

 public static void closeAll() {
  try {
   if (psmt != null) {
    psmt.close();
   }
   if (con != null) {

    con.close();

   }
   if (rs != null) {
    rs.close();
   }

  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }
}

 

package service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import dao.EmpInfoDao;
import bean.Empinfo;;

/**
 * userinfo业务服务类
 *
 * @author Administrator
 *
 */
public class EmpinfoServer {
 // 成员
 private EmpInfoDao empInfoDao = new EmpInfoDao();

 
 public Empinfo getEmpInfo(Empinfo empinfo) throws Exception {
  System.out.println(empinfo.getEmpName());

  return  empInfoDao.getEmpinfo(empinfo);

 }
 
 public boolean addEmpinfo(Empinfo empinfo) throws Exception{
  boolean res=false;
  int count;
  try {
   count=empInfoDao.addEmpinfo(empinfo);
   if(count==1){
    res=true;
   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return res;
  
 }
 

 **
  * 改
  */
 public boolean updateEmpinfo(Empinfo empinfo,Empinfo empinfo2) throws Exception{
  boolean res=false;
  int count;
  try {
   count=empInfoDao.updateEmpinfo(empinfo,empinfo2);
   if(count>0){
    res=true;
   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return res;
  
 }
 /**
  * 查
  */
 public ArrayList<Empinfo> selectEmpinfo(Empinfo empinfo) throws Exception{
  ArrayList<Empinfo> res=new ArrayList<Empinfo>();
  try {
   res=empInfoDao.selectEmpinfo(empinfo);
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return res;
  
 }
 public Empinfo selectEmpinfo2(Empinfo empinfo) throws Exception{
  Empinfo res=new Empinfo();
  try {
   res=empInfoDao.selectEmpinfo2(empinfo);
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return res;
  
 }
 
 /**
  * 全部查询
  */
 public ArrayList<Empinfo> selectAllEmpinfo() throws Exception{
  ArrayList<Empinfo> res=new ArrayList<Empinfo>();
  try {
   res=empInfoDao.selectAllEmpinfo();
   
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return res;
  
 }
 
 
}

 

 

 

相关文章: