本站首页    管理页面    写新日志    退出


«November 2025»
1
2345678
9101112131415
16171819202122
23242526272829
30


公告

 

 好好学习        天天向上


我的分类(专题)

日志更新

最新评论

留言板

链接


Blog信息
blog名称:小鱼的空间
日志总数:18
评论数量:20
留言数量:0
访问次数:84648
建立时间:2006年7月6日




[”学习“]hibernate的crud
软件技术

taotao6086 发表于 2007/8/14 10:28:00

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;}


阅读全文(1554) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.410 second(s), page refreshed 144792071 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号