色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

Hibernate通用數據庫操作代碼

insert方法
復制代碼 代碼如下:
public void insert(Object o){Session session = HibernateSessionFactory.currentSession();Transaction t = session.beginTransaction();session.save(o);t.commit();HibernateSessionFactory.clossSession();}

delete方法
復制代碼 代碼如下:
public void delete(Object o,Serializable id){Session session = HibernateSessionFactory.currentSession():Transaction t = session.beginTransaction();Object o = session.get(o.class,id);if(o!=null){session.delete(o);}t.commit();HibernateSessionFactory.clossSession();}


update方法
復制代碼 代碼如下:
public void update(Object o,Serializable id){Session session = HibernateSessionFactory.currentSession();Transaction t = session.beginTransaction();session.update(o,id);t.commit();HibernateSessionFactory.clossSession();}

基于HQL的通用select方法
復制代碼 代碼如下:
public ArrayList select(String sql){Session session = HibernateSessionFactory.currentSession();Query query = createQuery(sql);List list = query.list();HibernateSessionFactory.clossSession();return (ArrayList)list;}

基于SQL的通用select方法
復制代碼 代碼如下:
public ArrayList select(String sql) throws Exception{Session session = HibernateSessionFactory.currentSession();Connection con = session.connection();PreparedStatement pstmt = con.preparedStatement(sql);ResultSet rs = pstmt.executeQuery();ResultSetMetaData rsmd = rs.getMetaData();Hashtable ht = null;ArrayList array = new ArrayList();while(rs.next()){ht = new Hashtable();for(int i=0;i<rsmd.getColumnCount();i++){ht.put(rsmd.getColumnName(i+1),rs.getObject(i+1));} array.add(ht);}HibernateSessionFactory.clossSession();return array;}

jsp技術Hibernate通用數據庫操作代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 牡丹江市| 自贡市| 华蓥市| 江阴市| 夏河县| 田阳县| 绥滨县| 广平县| 淄博市| 金山区| 永顺县| 吴川市| 和龙市| 安乡县| 高安市| 白山市| 称多县| 剑川县| 修水县| 屏山县| 闻喜县| 工布江达县| 响水县| 德江县| 石河子市| 巫溪县| 高清| 武穴市| 姚安县| 普定县| 云龙县| 仪陇县| 沂水县| 南昌市| 嘉禾县| 嘉善县| 金川县| 正镶白旗| 和静县| 濉溪县| 清河县|