赞
踩
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.Statement;
-
-
- public class MAIN {
- public static void main(String[] args) throws Exception {
- save();
- }
- public static void save() throws Exception{
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager
- .getConnection(
- "jdbc:mysql://localhost:3306/javadb",
- "root","1234");
- conn.setAutoCommit(false);
- System.out.println(conn.getAutoCommit()+"conn.getAutoCommit");
- PreparedStatement stmt = conn.prepareStatement("insert into t_stock (stockNo,qty) values ('001037',10)");
- try{
- stmt.executeUpdate();
- throw new RuntimeException();
- }catch(RuntimeException e){
- conn.rollback();
- e.printStackTrace();
- System.out.println("huigun...");
- }finally{
- if (stmt != null){
- stmt.close();
- }
- if (conn != null){
- conn.close();
- }
- }
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。