Java OCA OCP Practice Question 2047

Question

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


D.

Note

While the code turns off automatic committing, there is a commit() statement after the first two inserts that explicitly commits those to the database.

Then automatic commit is turned back on and the third commit is made, making Option D the answer.




PreviousNext

Related