事务1

http://it.hexun.com/2009-06-08/118437310.html http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=3116 http://www.blogjava.net/dreamstone/archive/2007/07/29/133077.html http://www.iteye.com/topic/177988# Class.forName("org.gjt.mm.mysql.Driver"); Connection conn=null; Statement st=null; boolean flag=false; String insertssql = "insert into st (id,name,sex,address) values (111,'2','3','4')"; String sel = "select * from st"; String del = "delete from st where id=11"; try { conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "zhouzhao"); st=conn.createStatement(); // conn.setAutoCommit(false); if(id.equals("del")) { st.executeUpdate(del); System.out.println("ddddddd"); conn.rollback(); }else{ ResultSet set = st.executeQuery(sel); while(set.next()){ System.out.println("id="+set.getObject("id")); } } // st.execute(sql2); // conn.commit(); flag=true; }catch(SQLException e){ try { conn.rollback(); } catch (SQLException e1) { } e.printStackTrace(); }finally{ try { if(st!=null) st.close(); if(conn!=null) conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }

 

 

 

 

 

 

jdbc事物 不主动提交事务,底层也会提交,但如果设置setAutoCommit(false);则不会提交;

hibernate 和jdbc的事物一致,但必须先开始事务,再提交。 jta管理事务的话,jta由容器管理connection,可以跨session。  spring管理事务不用主动提交

你可能感兴趣的:(spring,Hibernate,.net,mysql,jdbc)