accountdaohbnimpl.java
来自「加拿大达内科技有限公司配需java程序员的上课时的代码」· Java 代码 · 共 61 行
JAVA
61 行
package com.sd0709.bank.persistent;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.sd0709.bank.biz.entity.Account;
import com.sd0709.bank.util.HbnUtil;
public class AccountDAOHbnImpl implements IAccountDAO {
public void delete(String actNo) throws DataException {
try {
Session s = HbnUtil.getCurrentSession();
Account a = findByActNo(actNo);
s.delete(a);
} catch (HibernateException e) {
e.printStackTrace();
throw new DataException("delete error");
}
}
public Account findByActNo(String actNo) throws DataException {
Account a = null;
String hql ="from Account a " +
"where a.actNo=?";
try {
Session s = HbnUtil.getCurrentSession();
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) throws DataException {
try {
Session s = HbnUtil.getCurrentSession();
s.save(act);
} catch (HibernateException e) {
e.printStackTrace();
throw new DataException("save error");
}
}
public void update(Account act) throws DataException {
try {
Session s = HbnUtil.getCurrentSession();
s.update(act);
} catch (HibernateException e) {
e.printStackTrace();
throw new DataException("update error");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?