How many records will be inserted into the retweets table after executing the following code:
String insert = "INSERT INTO retweets VALUES (?, ?)";
try (Connection con = dataSource.getConnection()) {
con.setAutoCommit(false);
Savepoint savepoint0 = con.setSavepoint();
try (PreparedStatement retweetsPreparedStatement = con.prepareStatement(insert)) {
for (int i = 0; i < 10; i++) {
Savepoint savepoint1 = con.setSavepoint();
String text = "Congratulations to the Astronauts that left Earth today. Good choice";
retweetsPreparedStatement.setInt(1, i);
retweetsPreparedStatement.setString(2, text);
retweetsPreparedStatement.executeUpdate();
Savepoint savepoint2 = con.setSavepoint();
if (i < 5) {
con.rollback(savepoint1);
} else if (i < 9) {
con.rollback(savepoint2);
} else {
con.commit();
}
}
} catch (SQLException e) {
con.rollback(savepoint0);
}
} catch (SQLException e) {
e.printStackTrace();
}