📄 accountdaohbnimpl.java
字号:
package com.csd080111.bank.persistent;
/*
* 数据类
* 实现IAccountDAO 里的全部方法
* 方法:1、插入数据 2、删除数据 3、更新数据 4、查找数据
*/
import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.csd080111.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 {
Account a = null;
s.save(act);
} catch (HibernateException e) {
e.printStackTrace();
throw new DataException("insert 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -