(1)基本使用

  • setAutoCommit(false);
  • rollback();
  • commit();
    1. Connection connection = null;
    2. PreparedStatement statement = null;
    3. ResultSet resultSet = null;
    4. try {
    5. connection = JDBCUtils.getConnection();
    6. connection.setAutoCommit(false);
    7. // 数据库各类操作
    8. connection.commit();
    9. } catch (Exception e) {
    10. if (connection != null){
    11. try {
    12. connection.rollback();
    13. } catch (SQLException e1) {
    14. e1.printStackTrace();
    15. }
    16. }
    17. } finally {
    18. JDBCUtils.close(resultSet, statement, connection);
    19. }