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

📄 deptdao.java

📁 含有 销售商、进货商
💻 JAVA
字号:
package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import po.DeptPO;
import vo.incomeVO;

public class DeptDAO {
	
	Connection conn = null;
	Statement state = null;
	ResultSet rs = null;
	
	//查询符合部门ID号的记录
	public DeptPO FindByID(int id)
	{
		DeptPO dept = null;
		try {
			conn = Tools.getConnection();
			state = conn.createStatement();
			rs = state.executeQuery("select * from table_dept where dept_id = " + id);
			
			if(rs.next())
			{
				dept = new DeptPO();
				dept.setDept_id(rs.getInt("dept_id"));
				dept.setDept_name(rs.getString("dept_name"));
				dept.setDept_descreption(rs.getString("dept_descreption"));
			}
				
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				rs.close();
				state.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return dept;
	}
	
    //修改table_dept记录
    public boolean Update(DeptPO po )
    {
    	boolean isdk = false;
    	try {
    		
    		conn = Tools.getConnection();
			state = conn.createStatement();
			if(state.executeUpdate("update table_dept set dept_name = '"+po.getDept_name()+"',dept_descreption = '"+po.getDept_descreption()+"' where dept_id = " + po.getDept_id())>0)
			{
				isdk = true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	finally
    	{
    		try {
				state.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    	return isdk;
    }
    
    //遍历Table_Dept表
	public ArrayList listDept()
	{
		ArrayList array = new ArrayList();
		IncomeDAO dao = new IncomeDAO();
		DeptPO po = null;
		try {
			conn = Tools.getConnection();
			state = conn.createStatement();
			rs = state.executeQuery("select * from table_dept" );
			
			while(rs.next())
			{
				po = new DeptPO();
				po.setDept_id(rs.getInt("dept_id"));
				po.setDept_name(rs.getString("dept_name"));
				po.setDept_descreption(rs.getString("dept_descreption"));
				
				array.add(po);
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				rs.close();
				state.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return array;
	}
	
	//向Table_Dept表中添加记录
	public boolean AddDept(DeptPO po)
	{
		boolean isdk = false;
		try {
			conn = Tools.getConnection();
			state = conn.createStatement();
			if(state.executeUpdate("insert into table_dept values("+po.getDept_id()+",'"+po.getDept_name()+"','"+po.getDept_descreption()+"')")>0)
			{
				isdk = true;
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				state.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return isdk;
	}
	
    //查找部门的ID号
	public int addDeptId(String dept)
	{
		int deptID = 0;
		try {
			conn = Tools.getConnection();
			state = conn.createStatement();
			rs = state.executeQuery("select * from table_dept where dept_name = '"+ dept+"'" );
			
			if(rs.next())
			{
				deptID = rs.getInt("dept_id");
			}
				
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				rs.close();
				state.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return deptID;
	}
	
    //自动累加ID
	public int addDeptID()
	{
		int id = 0;
		try {
			conn = Tools.getConnection();
			state = conn.createStatement();
			rs = state.executeQuery("select max(dept_id) Mid from table_dept  ");
			
			if(rs.next())
			{
				id = rs.getInt("Mid");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				rs.close();
				state.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return ++id;
	}
    

}

⌨️ 快捷键说明

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