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

📄 logdao.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.List;

import com.oa.lp.model.CommLinkMan;
import com.oa.lp.model.Inform;
import com.oa.lp.model.Log;
import com.oa.lp.util.DTOPopulator;

public class LogDAO {
	private Connection conn;
	
	public Connection getConn() {
		return conn;
	}

	public void setConn(Connection conn) {
		this.conn = conn;
	}
	
	
	/**
	 * 新增日志
	 * @param menu
	 * @throws SQLException
	 */
	public void addLog(Log log,int empId) throws SQLException{

		String sql = "insert into LOG(EMP_ID,LOG_TIME,LOG_CONTENT)values(?,getDate(),?)";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1,empId);
		pstmt.setString(2,log.getLogContent());
		
		pstmt.executeUpdate();
		pstmt.close();
	}
	/**
	 * 通过Id获得日志
	 * @param logId
	 * @return
	 * @throws Exception
	 */
	public Log getLogById(int logId) throws Exception{
		Log log = new Log();
		List list=null;
		String sql = "select *from LOG where LOG_ID=?";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1,logId);
		ResultSet rs = pstmt.executeQuery();
		list = DTOPopulator.populate(rs, Log.class);
		if(list.size()>0){
			log = (Log)list.get(0);
		}
		rs.close();
		pstmt.close();
		return log;
	}
	
	
	public void updateLog(Log log,int empId) throws SQLException{
		String sql = "update LOG set EMP_ID=?,LOG_TIME=?,LOG_CONTENT=? where LOG_ID=?";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		
		pstmt.setInt(1,empId);
		pstmt.setDate(2,log.getLogTime());
		pstmt.setString(3,log.getLogContent());
		pstmt.setInt(4,log.getLogId());
		pstmt.executeUpdate();
		pstmt.close();
	}
	
	/**
	 * 通过
	 * @param empId
	 * @return
	 * @throws Exception员工的ID的到其日志
	 */
	public List listAllLogs(int empId) throws Exception{
		List list = null; 
		String sql = "select * from LOG where EMP_ID=?";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1,empId);
		ResultSet rs = pstmt.executeQuery();
		//将结果集中的每一行记录封装成一个对象,再放进集合返回
		list = DTOPopulator.populate(rs, Log.class);
		pstmt.close();
		return list;
	}
	
	/**
	 * 删除日志
	 * @throws SQLException 
	 */
	
	public void delLog(int logId) throws SQLException{
		String sql = "delete from LOG where LOG_ID=?";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1,logId);
		pstmt.executeUpdate();
		pstmt.close();
		
	}
}

⌨️ 快捷键说明

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