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

📄 dao.java

📁 企业员工信息管理C/S模式
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com;

import java.sql.*;
import model.*;
public class DAO {
	private static Connection conn = null;
	private static String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
	//private static String driver = "oracle.jdbc.driver.OracleDriver";
	private static String url = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=EmployeeManager";
	//private static String url = "jdbc:oracle:thin:@localhost:1521:NEUSOFT";
    private static String user = "sa";
	private static String pwd = "pass";
	/**
	 * 连接数据库
	 * @return
	 */
	public static Connection getConnection(){
		try{
			Class.forName(driver).newInstance();
			conn = DriverManager.getConnection(url,user,pwd);
			if(conn!=null){
				System.out.println("连接sql server数据库成功!");
			}
		}catch(Exception ex){
			ex.printStackTrace();
			System.out.println(ex.getMessage());
		}
		return conn;
	}
	/**
	 * 查询专业名称
	 * @return
	 */
	public static ResultSet getSpecialname(){
		String sql = "select sname from tb_special";
		ResultSet rs = DAO.getResultSet(sql);
		return rs;
	}
	/**
	 * 查询岗位名称
	 * @return
	 */
	public static ResultSet getStationname(){
		String sql = "select stationname from tb_stationinfo";
		ResultSet rs = DAO.getResultSet(sql);
		return rs;
	}
	/**
	 *  得到所有部门
	 * @return
	 */
	public static ResultSet getDeptKind(){
		conn = DAO.getConnection();
		Statement stmt = null;
		ResultSet rs = null;
		try{
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select dkind from tb_deptkind");
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
		}
		return rs;
	}
	/**
	 * 得到部门名称
	 * @param dname
	 * @return
	 */
	public static ResultSet getDeptName(String name){
		conn = DAO.getConnection();
		Statement stmt = null;
		ResultSet rs1 = null;
		ResultSet rs2 = null;
		try{
			stmt = conn.createStatement();
			rs1 = stmt.executeQuery("select dkid from tb_deptkind where dkind='"+name+"'");
			while(rs1.next()){
				rs2 = stmt.executeQuery("select dname from tb_deptinfo where dkid="+rs1.getInt(1)+"");
			}
		}catch(Exception e){
			//e.printStackTrace();
			System.out.println(e.getMessage());
		}
		return rs2;
	}
	/**
	 * 查询部门id
	 * @return
	 */
	public static ResultSet getDeptID(){
		String sql = "select dkid from tb_deptkind";
		ResultSet rs = DAO.getResultSet(sql);
		return rs;
	}
	/**
	 * 得到员工信息
	 * @return
	 */
	public static ResultSet getEmployee(){
		conn = DAO.getConnection();
		ResultSet rs = null;
		Statement stmt = null;
		try{
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select * from tb_employee");
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return rs;
	}
	/**
	 * 查询指定的员工信息
	 * @param id
	 * @return
	 */
	public static TbEmployeeInfo getSpeEmployee(int id){
		TbEmployeeInfo info = new TbEmployeeInfo();
		conn = DAO.getConnection();
		
		ResultSet rs = null;
		try{
			Statement stmt = conn.createStatement();
			rs = stmt.executeQuery("select * from tb_employee where empid="+id+"");
			while(rs.next()){
				info.setEname(rs.getString("ename"));
				info.setEyname(rs.getString("eyname"));
				info.setSex(rs.getString("sex"));
				info.setBirthday(rs.getString("birthday"));
				info.setNativeplace(rs.getString("nativeplace"));
				info.setNation(rs.getString("nation"));
				info.setHkszd(rs.getString("hkszd"));
				info.setBornaddress(rs.getString("bornaddress"));
				info.setCommnityname(rs.getString("commnityname"));
				info.setFirstedu(rs.getString("firstedu"));
				info.setEducation(rs.getString("education"));
				info.setSchool(rs.getString("school"));
				info.setSpecialname(rs.getString("specialname"));
				info.setIntoschooldate(rs.getString("intoschooldate"));
				info.setGraduatedate(rs.getString("graduatedate"));
				info.setIsfirstedu(rs.getString("isfirstedu"));
				info.setDegree(rs.getString("degree"));
				info.setEduyears(rs.getInt("eduyears"));
				info.setStudyway(rs.getString("studyway"));
				info.setPolityface(rs.getString("polityface"));
				info.setIntopartydate(rs.getString("intoparydate"));
				info.setWorkway(rs.getString("workway"));
				info.setDutyname(rs.getString("dutyname"));
				info.setBeginworkdate(rs.getString("beginworkdate"));
				info.setIntodeptdate(rs.getString("intodeptdate"));
				info.setWorkstate(rs.getString("workstate"));
				info.setRetireddate(rs.getString("retireddate"));
				info.setGrsf(rs.getString("grsf"));
				info.setBgphone(rs.getString("bgphone"));
				info.setSjphone(rs.getString("sjphone"));
				info.setHomephone(rs.getString("homephone"));
				info.setFyzymark(rs.getString("fyzymark"));
				info.setIdcard(rs.getString("idcard"));
				info.setXxdate(rs.getString("xxdate"));
				info.setLdhtid(rs.getString("ldhtid"));
				info.setDeptno(rs.getInt("deptno"));
				info.setClassname(rs.getString("classname"));
				info.setMenu(rs.getString("menu"));
			}
		}catch(Exception ex){
			System.out.println(ex.getMessage());
		}
		return info;
	}
	
	/**
	 *  修改员工信息
	 * @param info
	 * @return
	 */
	public static boolean updateSpeEmployee(TbEmployeeInfo info){
		String sql = "update tb_employee set ename='"+info.getEname()+"',eyname='"+info.getEyname()+
		"',sex='"+info.getSex()+"',birthday='"+info.getBirthday()+"',nativeplace='"+info.getNativeplace()+
		"',nation='"+info.getNation()+"',hkszd='"+info.getHkszd()+"',bornaddress='"+info.getBornaddress()+
		"',commnityname='"+info.getCommnityname()+"',firstedu='"+info.getFirstedu()+"',education='"+info.getEducation()+
		"',school='"+info.getSchool()+"',intoschooldate='"+info.getIntoschooldate()+
		"',graduatedate='"+info.getGraduatedate()+"',isfirstedu='"+info.getIsfirstedu()+"',degree='"+info.getDegree()+
		"',eduyears="+info.getEduyears()+",studyway='"+info.getStudyway()+"',polityface='"+info.getPolityface()+
		"',intoparydate='"+info.getIntopartydate()+"',workway='"+info.getWorkway()+"',dutyname='"+info.getDutyname()+
		"',spedutyname='"+info.getSpedutyname()+"',beginworkdate='"+info.getBeginworkdate()+"',intodeptdate='"+info.getIntodeptdate()+
		"',workstate='"+info.getWorkstate()+"',retireddate='"+info.getRetireddate()+"',grsf='"+info.getGrsf()+"',bgphone='"+info.getBgphone()+
		"',sjphone='"+info.getSjphone()+"',homephone='"+info.getHomephone()+"',fyzymark='"+info.getFyzymark()+
		"',idcard='"+info.getIdcard()+"',xxdate='"+info.getXxdate()+"',ldhtid='"+info.getLdhtid()+
		"',deptno="+info.getDeptno()+",classname='"+info.getClassname()+"',menu='"+info.getMenu()+"' where empid="+info.getEmpid()+"";
		conn = DAO.getConnection();
		Statement stmt = null;
		try{
			stmt = conn.createStatement();
			int count = stmt.executeUpdate(sql);
			if(count>0)
				return true;
			else
				return false;
		}catch(Exception ex){
			System.out.println(ex.getMessage());
			return false;
		}
	}
	/**
	 * 添加部门名称
	 * @param name
	 * @return
	 */
	public static boolean addDept(String name){
		conn = DAO.getConnection();
		ResultSet rs = null;
		Statement stmt = null;
		try{
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select * from tb_deptkind where dkind='"+name+"'");
			if(!rs.next()){
				int count = stmt.executeUpdate("insert into tb_deptkind values('"+name+"')");
				if(count>0){
					return true;
				}else{
					return false;
				}
			}else{
				return false;
			}
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	/**
	 * 修改部门名称
	 * @param yname
	 * @param nname
	 * @return
	 */
	public static boolean updateDept(String yname,String nname){
		conn = DAO.getConnection();
		Statement stmt = null;
		try{
			stmt = conn.createStatement();
			int count = stmt.executeUpdate("update tb_deptkind set dkind='"+nname+"' where dkind='"+yname+"'");
			if(count>0)
				return true;
			else
				return false;
			}catch(Exception e){
				e.printStackTrace();
				return false;
			}
	}
	/**
	 * 删除部门
	 * @param name
	 * @return
	 */
	public static boolean deleteDept(String name){
		conn = DAO.getConnection();
		int id = 0;
		Statement stmt = null;
		ResultSet rs = null;
		ResultSet rs1 = null;
		try{
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select dkid from tb_deptkind where dkind='"+name+"'");
			while(rs.next()){
				id = rs.getInt(1);
			}
			rs1 = stmt.executeQuery("select * from tb_deptinfo where dkid="+id+"");
			if(rs1.next()){
				return false;
			}else{
				int count = stmt.executeUpdate("delete from tb_deptkind where dkind='"+name+"'");
				if(count>0){
					return true;
				}else{
					return false;
				}
			}
		}catch(Exception e){
			System.out.println(e.getMessage());
			return false;
		}
	}
	/**
	 * 查询empid
	 * @return
	 */
	public static ResultSet getEmployeeId(){
		conn = DAO.getConnection();
		ResultSet rs = null;
		Statement stmt = null;
		try{
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select empid from tb_employee");
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		return rs;
	}
	/**
	 * 查询ename
	 * @return
	 */
	public static ResultSet getEmployeeName(){
		String sql = "select ename from tb_employee";
		ResultSet rs = getResultSet(sql);
		return rs;
	}
	/**
	 * 查询dutyname
	 * @return
	 */

⌨️ 快捷键说明

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