我有多个准备好的陈述。我需要为每条语句执行“connection.commit”还是在最后一条语句之后只调用一次?
Connection connection = datasource.getConnect();
connection.setAutoCommit(false);
PreparedStatement pstmt1 = connection.prepareStatement(query1);
pstmt1.executeUpdate();
connection.commit();
PreparedStatement pstmt2 = connection.prepareStatement(query2);
pstmt2.executeUpdate();
connection.commit();
PreparedStatement pstmt3 = connection.prepareStatement(query3);
pstmt3.executeUpdate();
connection.commit();
Or
Connection connection = datasource.getConnect();
connection.setAutoCommit(false);
PreparedStatement pstmt1 = connection.prepareStatement(query1);
pstmt1.executeUpdate();
PreparedStatement pstmt2 = connection.prepareStatement(query2);
pstmt2.executeUpdate();
PreparedStatement pstmt3 = connection.prepareStatement(query3);
pstmt3.executeUpdate();
connection.commit();
谢谢。