ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 原生JDBC实例 ~~~ Connection connection = null; int i = 0; int j = 0; try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://192.168.10.10:3306/jdbc", "homestead", "secret"); connection.setAutoCommit(false); PreparedStatement preparedStatement1 = connection.prepareStatement("update account set money = money - 1000 where name = 'jack'"); PreparedStatement preparedStatement2 = connection.prepareStatement("update account set money = money + 1000 where name = 'tom'"); i = preparedStatement1.executeUpdate(); j = preparedStatement2.executeUpdate(); // System.out.println(1 / 0); connection.commit(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { try { connection.rollback(); } catch (SQLException sql) { e.printStackTrace(); } e.printStackTrace(); } finally { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } ~~~