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); /* w ww . j av a 2 s . c o m*/ stmt.executeUpdate("insert into colors values ('red')"); stmt.executeUpdate("insert into colors values ('blue')"); conn.rollback(); conn.setAutoCommit(true); stmt.executeUpdate("insert into colors values ('green')"); }
B.
The code turns off automatic committing, so the inserts for red and blue are not immediately made.
The rollback()
statement actually prevents them from being committed.
Then automatic commit is turned back on and one insert is made, making Option B the answer.