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

📄 sharefiledao.java

📁 一个jsp的oa系统,里面有很多亮点学习!
💻 JAVA
字号:
package com.oa.lp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.oa.lp.model.Company;
import com.oa.lp.model.File;
import com.oa.lp.util.DTOPopulator;

public class ShareFileDAO {
	private Connection conn;

	public Connection getConn() {
		return conn;
	}

	public void setConn(Connection conn) {
		this.conn = conn;
	}
	
	/**
	 * 删除员工拥有的文件
	 * @throws SQLException 
	 */
	public void delFileEmp(int fileId) throws SQLException{
		String sql = "delete from SHARE_FILE where FILE_ID=?";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1,fileId);
		pstmt.executeUpdate();
		pstmt.close();
	}
	/**
	 * 为员工分配文件
	 * @throws SQLException 
	 */
	
	public void addFileEmp(int fileId,String empIds[]) throws SQLException{
		String sql = "insert into SHARE_FILE(FILE_ID,EMP_ID) VALUES(?,?)";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		for(int i=1;i<empIds.length;i++){
			pstmt.setInt(1,fileId);
			pstmt.setInt(2,Integer.parseInt(empIds[i]));
			pstmt.executeUpdate();
		}
		pstmt.close();
	}
	
	/**
	 * 通过文件查找文件的共享员工
	 * @throws SQLException 
	 */
	public List getEmpByFileId(int fileId) throws SQLException{
		List list = new ArrayList();
		String sql="select *from SHARE_FILE where FILE_ID=?";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1,fileId);
		ResultSet rs = pstmt.executeQuery();
		while(rs.next()){
			int empId = rs.getInt("EMP_ID");
			list.add(String.valueOf(empId));
		}
		return list;
	}
	
	/**
	 * 通过员工ID得到其共享文件
	 * @throws Exception 
	 */
	
	public File getFileByEmpId(int empId) throws Exception{
		File file = new File();
		List list = null;
		String sql = "select * from [FILE] where FILE_ID in (select FILE_ID from SHARE_FILE where EMP_ID=1)";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1,empId);
		ResultSet rs = pstmt.executeQuery();
		list = DTOPopulator.populate(rs, File.class);
		if(list.size()>0){
			file = (File)list.get(0);
		}
		rs.close();
		pstmt.close();
		return file;
	}
}

⌨️ 快捷键说明

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