Given the following code:
String insertLanguage = "INSERT INTO languages (id, name) VALUES (?, ?)";
String insertApplication = "INSERT INTO applications (id, name, language_id) VALUES (?, ?, ?)";
public void insertNewLanguageAndApplication(Connection con, Application application) {
try (PreparedStatement languagePreparedStatement = con.prepareStatement(insertLanguage);
PreparedStatement applicationPreparedStatement = con.prepareStatement(insertApplication)) {
if (con.getAutoCommit()) {
{1}
}
Language language = application.getLanguage();
languagePreparedStatement.setInt(1, language.getId());
languagePreparedStatement.setString(2, language.getName());
languagePreparedStatement.executeUpdate();
applicationPreparedStatement.setInt(1, application.getId());
applicationPreparedStatement.setString(2, application.getName());
applicationPreparedStatement.setInt(3, language.getId());
applicationPreparedStatement.executeUpdate();
{2}
} catch ({3} e) {
e.printStackTrace();
{4}
}
}
Match missed parts of the code to disable auto-commit mode and commit all transaction changes if each statement executes successfully, otherwise rollback the transaction.