爱问知识人 爱问教育 医院库

Hibernate如何编写通用数据库操作代码?

首页

Hibernate如何编写通用数据库操作代码?

Hibernate如何编写通用数据库操作代码?

提交回答

全部答案

    2017-07-28 11:56:06
  •   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 ht。put(rsmd。getColumnName(i+1),rs。getObject(i+1)); } array。add(ht); } HibernateSessionFactory。
      clossSession(); return array; }。

    邹***

    2017-07-28 11:56:06

类似问题

换一换
  • 系统软件 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):