[Java] Transaction →→→→→进入此内容的聊天室

来自 , 2019-06-29, 写在 Java, 查看 108 次.
URL http://www.code666.cn/view/5dd9db5e
  1. import java.sql.*;
  2. public class Transaction2 {
  3.         public static void main(String[] args) {
  4.                 Statement stmt = null;
  5.                 Connection conn = null;
  6.                 try {
  7.                         Class.forName("");
  8.                         conn = DriverManager.getConnection("");
  9.                         conn.setAutoCommit(false);
  10.                         stmt = conn.createStatement();
  11.                         stmt.addBatch(sql);
  12.                         conn.setAutoCommit(true);
  13.                 } catch (ClassNotFoundException e) {
  14.                         e.printStackTrace();
  15.                 } catch (SQLException e) {
  16.                         try {
  17.                                 if(conn != null) {
  18.                                         conn.rollback();
  19.                                         conn.setAutoCommit(true);
  20.                                 }
  21.                         } catch (SQLException e1) {
  22.                                         e.printStackTrace();
  23.                         }
  24.                                
  25.                 } finally {
  26.                         try {
  27.                                 if(stmt != null) {
  28.                                         stmt = null;
  29.                                         stmt.close();
  30.                                 }
  31.                                 if(conn != null) {
  32.                                         conn = null;
  33.                                         conn.close();
  34.                                 }
  35.                         } catch (SQLException e) {
  36.                                 e.printStackTrace();
  37.                         }
  38.                 }
  39.         }      
  40. }
  41.  

回复 "Transaction"

这儿你可以回复上面这条便签

captcha