How many rows are added to the colors table from running the following?



How many rows are added to the colors table from running the following?

try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement()) {
    conn.setAutoCommit(false);
    stmt.executeUpdate("insert into colors values ('red')");
    stmt.executeUpdate("insert into colors values ('blue')");
    conn.commit();
    conn.setAutoCommit(true);
    stmt.executeUpdate("insert into colors values ('green')");
}
A. None
B. One
C. Two
D. Three

Answer

B. One

Explanation:

The code turns off automatic committing, so the inserts for red and blue are not immediately made. 
The rollback(a) statement actually prevents them from being committed. Then automatic commit is turned back on and one insert is made, making Option B the answer.

Free Spring Boot Tutorial - 5 Hours Full Course


Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course

Comments