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

📄 a083812b67ac001d105fa91adc11449d

📁 超好用的企业员工信息管理系统
💻
字号:
package com;

import java.sql.*;

public class DAO {
	private static Connection conn = null;
	private static String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
	//private static String driver = "oracle.jdbc.driver.OracleDriver";
	private static String url = "jdbc:odbc:JDBC_ODBC";
	//private static String url = "jdbc:oracle:thin:@localhost:1521:NEUSOFT";
	//private static String user = "SCOTT";
	//private static String pwd = "TIGER";
	//private static Statement stmt = null;
	//private static ResultSet rs = null;
	private static ResultSet rs1 = null;
	/**
	 * 连接数据库
	 * @return
	 */
	public static Connection getConnection(){
		try{
			Class.forName(driver).newInstance();
			conn = DriverManager.getConnection(url);
			if(conn!=null){
				System.out.println("连接sql server数据库成功!");
			}
		}catch(Exception ex){
			System.out.println(ex.getMessage());
		}
		return conn;
	}
	/**
	 *  得到所有部门
	 * @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){
			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){
			System.out.println(e.getMessage());
		}
		return rs2;
	}
	/**
	 * 得到员工信息
	 * @return
	 */
	public static ResultSet getEmployee(){
		conn = DAO.getConnection();
		ResultSet rs = null;
		return rs;
	}
	/**
	 * 添加部门名称
	 * @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 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;
		}
	}
	/**
	 * 关闭数据源
	 *
	 */
	public static void closeconn(){
		if(rs!=null){
			try{
				rs.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		if(stmt!=null){
			try{
				stmt.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try{
				conn.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}

}

⌨️ 快捷键说明

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