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("修改成功"); 

  • 相关阅读:
    Codeforces 469D Two Sets
    Codeforces1249D2 Too Many Segments (hard version)
    Codeforces 796D Police Stations
    Codeforces 617E XOR and Favorite Number
    Codeforces 900D Unusual Sequences
    Python底层(一):列表
    最短路径笔记(一):Floyd
    竞赛题笔记(二):剪邮票
    图论题笔记(三):最少中转次数
    图论题笔记(二):城市地图
  • 原文地址:https://www.cnblogs.com/OP-RONG/p/4200291.html
Copyright © 2011-2022 走看看