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

📄 affichedaoimpl.java

📁 一个oa系统
💻 JAVA
字号:
package com.oa.db;

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

import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class AfficheDAOImpl extends HibernateDaoSupport implements AfficheDAO {

	public void addAffiche(Affiche affiche) {
		// TODO 自动生成方法存根
		Connection conn = getHibernateTemplate().getSessionFactory().openSession().connection();
		CallableStatement cstmt = null;
		try {
			cstmt = conn.prepareCall("{call add_affiche(?,?,?,?)}");
			cstmt.setString(1, affiche.getAfficheTitle());
			cstmt.setInt(2, affiche.getDeptId());
			cstmt.setString(3, affiche.getAfficheContent());
			cstmt.setString(4, affiche.getEmpId());
			cstmt.executeUpdate();			
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} finally {
			try {
				if (cstmt != null) {
					cstmt.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (Exception e) {
				// TODO: handle exception
			}
		}

	}

	public void deleteAffiche(Affiche affiche) {
		// TODO 自动生成方法存根
		try { 
			getHibernateTemplate().delete(affiche);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Affiche findOneAfficheByAfficheId(String afficheId) {
		// TODO 自动生成方法存根
		String sql = "from Affiche where affiche_id=?";
		Affiche affiche = new Affiche();
		if (getHibernateTemplate().find(sql, afficheId) != null) {
			affiche = (Affiche) getHibernateTemplate().find(sql, afficheId).get(0);
		}
		return affiche;
	}

	public ArrayList<Affiche> showMenberAfficheByDeptId(int start, int deptId) {
		// TODO 自动生成方法存根
		ArrayList<Affiche> afficheList = new ArrayList<Affiche>();
		String str = "select *from affiche where dept_id =" + deptId + " limit " + start + ",15";
		Connection conn = getHibernateTemplate().getSessionFactory().openSession().connection();
		PreparedStatement pstmt = null;
		try {
			pstmt = conn.prepareStatement(str);
			ResultSet rst = pstmt.executeQuery();
			while (rst.next()) {
				Affiche affiche = new Affiche();
				affiche.setAfficheTitle(rst.getString("affiche_title"));
				affiche.setAfficheId(rst.getString("affiche_id"));
				affiche.setCreateTime(rst.getString("create_time"));
				affiche.setEmpId(rst.getString("emp_id"));
				afficheList.add(affiche);
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch
			e.printStackTrace();
		} finally {
			try {
				if (pstmt != null) {
					pstmt.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (Exception e) {
				// TODO: handle exception
			}
		}

		return afficheList;
	}

	public void updateAffiche(Affiche affiche) {
		// TODO 自动生成方法存根
		getHibernateTemplate().update(affiche);
	}

	public int getRecordByDeptId(int deptId) {
		// TODO 自动生成方法存根
		int i = 0;
		String sql = "select count(*) from Affiche where dept_id =?";
		i = Integer.parseInt(getHibernateTemplate().find(sql, "" + deptId).get(0).toString());
		return i;
	}

	public ArrayList<Affiche> showNewMenberAfficheByDeptId(int deptId) {
		// TODO 自动生成方法存根
		ArrayList<Affiche> afficheList = new ArrayList<Affiche>();
		String str = "select * from affiche where dept_id =" + deptId + " order by affiche_id DESC limit 0,5";
		Connection conn = getHibernateTemplate().getSessionFactory().openSession().connection();
		PreparedStatement pstmt = null;
		try {
			pstmt = conn.prepareStatement(str);
			ResultSet rst = pstmt.executeQuery();
			while (rst.next()) {
				Affiche affiche = new Affiche();
				affiche.setAfficheTitle(rst.getString("affiche_title"));
				affiche.setAfficheId(rst.getString("affiche_id"));
				affiche.setCreateTime(rst.getString("create_time"));
				affiche.setEmpId(rst.getString("emp_id"));
				afficheList.add(affiche);
			}

		} catch (SQLException e) {
			// TODO 自动生成 catch
			e.printStackTrace();
		} finally {
			try {
				if (pstmt != null) {
					pstmt.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (Exception e) {
				// TODO: handle exception
			}
		}

		return afficheList;
	}

}

⌨️ 快捷键说明

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