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

📄 deptdaoimpl.java

📁 一款仿msdn聊天程序,用java编写,很好用!
💻 JAVA
字号:
package org.lxh.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.lxh.dao.DeptDAO;
import org.lxh.factory.DefaultSessionFactory;
import org.lxh.vo.Dept;

public class DeptDAOImpl implements DeptDAO {
	private Session session = null;

	public DeptDAOImpl() {
		this.session = DefaultSessionFactory.getSession();
	}

	public void delete(String deptno) throws Exception {
		String hql = "DELETE FROM Dept WHERE deptno=?";
		Query q = this.session.createQuery(hql);
		q.setString(0, deptno);
		q.executeUpdate();
		this.session.beginTransaction().commit();
	}

	public void insert(Dept dept) throws Exception {
		this.session.save(dept);
		this.session.beginTransaction().commit();
		this.session.close();
	}

	public List queryAll() throws Exception {
		List all = null;
		String hql = "FROM Dept AS d";
		Query q = this.session.createQuery(hql);
		all = q.list();
		this.session.close();
		return all;
	}

	public Dept queryByDeptno(String deptno) throws Exception {
		Dept d = null;
		String hql = "FROM Dept AS d WHERE d.deptno=?";
		Query q = this.session.createQuery(hql);
		q.setString(0, deptno);
		List all = q.list();
		if (all.size() > 0) {
			d = (Dept) all.get(0);
		}
		d.getEmps().hashCode();
		this.session.close();
		return d;
	}

	public List queryByLike(String cond) throws Exception {
		List all = null;
		String hql = "FROM Dept AS d WHERE d.dname LIKE ? OR d.loc LIKE ? OR d.business LIKE ?";
		Query q = this.session.createQuery(hql);
		q.setString(0, "%" + cond + "%");
		q.setString(1, "%" + cond + "%");
		q.setString(2, "%" + cond + "%");
		all = q.list();
		this.session.close();
		return all;
	}

	public void update(Dept dept) throws Exception {
		this.session.update(dept);
		this.session.beginTransaction().commit();
		this.session.close();
	}

}

⌨️ 快捷键说明

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