zoukankan      html  css  js  c++  java
  • Hibernate的四种典型例子(增删改查)

     Hibernate的四种典型例子(增删改查) 
    //查询 
    // Session session=HibernateSessionFactory.getSession(); 
    // session.beginTransaction(); 
    // Query q=session.createQuery("from Info where id=:id"); 
    // q.setInteger("id", 1); 
    // List l=q.list(); 
    // Info i=(Info)l.get(0); 
    // System.out.print(i.getName()+i.getPwd()); 
    // System.out.println("查询成功"); 
    //删除
    // Session session=HibernateSessionFactory.getSession(); 
    // Transaction t=session.getTransaction(); 
    // t.begin(); 
    // Query q=session.createQuery("from Info where name=:name"); 
    // q.setString("name", "kk"); 
    // List l=q.list(); 
    // Info info=(Info)l.get(0); 
    // session.delete(info); 
    // t.commit(); 
    // System.out.print("删除成功"); 
    //添加 
    // Session session=HibernateSessionFactory.getSession(); 
    // Transaction t=session.getTransaction(); 
    // t.begin(); 
    // Info info=new Info(); 
    // info.setId(3); 
    // info.setName("k9999"); 
    // info.setPwd("333"); 
    // session.save(info); 
    // t.commit(); 
    // System.out.print("添加成功"); 

    //修改
    // Session session=HibernateSessionFactory.getSession(); 
    // Transaction t=session.getTransaction(); 
    // t.begin(); 
    // Info info=new Info(); 
    // info.setId(2); 
    // info.setName("dafei"); 
    // info.setPwd("shazi"); 
    // session.update(info); 
    // t.commit(); 
    // System.out.print("修改成功"); 

  • 相关阅读:
    缺省参数的注意事项
    可变和不可变类型
    Python之旅
    BBS项目 个人界面分类,文章,模板的使用详解
    Django 模板
    BBS项目 部分主界面and个人博客界面代码详解
    BBS项目 注册界面and部分首页代码详解
    BBS项目 备忘时时更新
    BBS项目 登录界面代码详解
    BBS项目 基本表关系
  • 原文地址:https://www.cnblogs.com/OP-RONG/p/4200291.html
Copyright © 2011-2022 走看看