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

📄 dbstudentimpl.java

📁 我们采用了JSP技术为主要手段,本系统采用了多级角色管理:包括系统管理员、系主任
💻 JAVA
字号:
package com.middle.graduate.biz.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.middle.graduate.biz.dao.DBStudentDao;
import com.middle.graduate.biz.entity.Student;
import com.middle.graduate.biz.entity.Topic;
import com.middle.graduate.biz.exce.DataException;
import com.middle.graduate.util.HbnUtil;

public class DBStudentImpl implements DBStudentDao {

	public void changePassword(int studentId, String password) throws DataException {
		Session session = HbnUtil.getSession();
		try {
			session.beginTransaction();
			String sql = "update t_student set t_password = ? where t_studentId = ?";
			session.createSQLQuery(sql).setString(0, password).setInteger(1, studentId).executeUpdate();
			session.getTransaction().commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			throw new DataException("db: student change password error");
		} finally {
			HbnUtil.closeSession();
		}
	}

	public boolean login(int studentId, String password) throws DataException {
		Session session = HbnUtil.getSession();
		try {
			session.beginTransaction();
			String sql = "select t_password from t_student where t_studentId = ?";
			String pwd = (String)session.createSQLQuery(sql).setInteger(0, studentId).uniqueResult();
			if(pwd.equals(password)) {
				return true;
			} else {
				return false;
			}
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new DataException("student login error");
		}
	}

	public List<Topic> queryAllTopic() throws DataException {
		Session session = HbnUtil.getSession();
		try {
			session.beginTransaction();
			String hql = "from Topic t order by t.topicId";
			List<Topic> list = session.createQuery(hql).list();
			return list;
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new DataException("db: student query all topic error");
		}
	}

	public Student querySelectedTopic(int studentId) throws DataException {
		Session session = HbnUtil.getSession();
		try {
			session.beginTransaction();
			String hql = "from Student s where s.studentId = ?";
			Student student = (Student)session.createQuery(hql).setInteger(0, studentId).uniqueResult();
			return student;
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new DataException("db: student query topic by id error");
		}
	}

	public void quitTopic(int studentId, int topicId) throws DataException {
		Session session = HbnUtil.getSession();
		try {
			session.beginTransaction();
			String sql = "update t_student, t_topic set f_topic = 0, t_topicState = 0 where t_studentId = ? and t_topicId = ?";
			session.createSQLQuery(sql).setInteger(0, studentId).setInteger(1, topicId).executeUpdate();
			session.getTransaction().commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			throw new DataException("db: student quit topic error");
		} finally {
			HbnUtil.closeSession();
		}
	}

	public void selectTopic(int studentId, int topicId) throws DataException {
		Session session = HbnUtil.getSession();
		try {
			session.beginTransaction();
			String sql = "update t_student, t_topic set f_topic = ?, t_topicState = 1 where t_studentId = ? and t_topicId = ?";
			session.createSQLQuery(sql).setInteger(0, topicId).setInteger(1, studentId).setInteger(2, topicId).executeUpdate();
			session.getTransaction().commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			throw new DataException("db: student select topic error");
		} finally {
			HbnUtil.closeSession();
		}
	}

}

⌨️ 快捷键说明

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