daohibernatetemplate.java
来自「此项目是实现,增加,删除,修改,查询图书数据库的功能」· Java 代码 · 共 51 行
JAVA
51 行
/*
* @(#) User.java 2007/09/01
*
* Copyright 2007 HeiBei Science & Technology University
*
* All rights reserved.
*/
package com.hevttc.book.template;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
/**
* 对数据库进行增,删,查,改的通用模板
*
* @author linzhen
*
*/
public class DaoHibernateTemplate {
public void find(ResultSession rs) {
Configuration cfg = null;
Session session = null;
try {
cfg = new Configuration().configure();
SessionFactory sf = cfg.buildSessionFactory();
session = sf.openSession();
Transaction ts = session.beginTransaction();
rs.resultSessionSet(session);
ts.commit();
} catch (HibernateException e) {
e.printStackTrace();
} finally {
if (session != null) {
try {
session.close();
} catch (HibernateException e) {
e.printStackTrace();
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?