Application language

Report a typo

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.

Match the items from left and right columns
1
2
3
4
SQLException
con.setAutoCommit(false);
con.commit();
con.rollback();
___

Create a free account to access the full topic