accountdaohbnimpl.java

来自「加拿大达内科技有限公司配需java程序员的上课时的代码」· Java 代码 · 共 56 行

JAVA
56
字号
package com.sd0709.bank.persistent;

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

import com.sd0709.bank.biz.entity.Account;

public class AccountDAOHbnImpl implements IAccountDAO {

	public void delete(String actNo, Session s) throws DataException {
		try {
			Account a = findByActNo(actNo,s);
			s.delete(a);
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new DataException("delete error");
		}
	}

	public Account findByActNo(String actNo, Session s) throws DataException {
		Account a = null;
		String hql ="from Account a " +
				"where a.actNo=?";
		try {
			a =(Account) s.createQuery(hql)
			     .setString(0, actNo)
			     .uniqueResult();
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new DataException("find error");
		}
		return a;
	}

	public void insert(Account act, Session s) throws DataException {
		try {
			s.save(act);
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new DataException("save error");
		}

	}

	public void update(Account act, Session s) throws DataException {
		try {
			s.update(act);
		} catch (HibernateException e) {
			e.printStackTrace();
			throw new DataException("update error");
		}

	}

}

⌨️ 快捷键说明

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