What is the result of the employees table has no records before the code executed?

Given the code fragment:

What is the result of the employees table has no records before the code executed?

Given the code fragment:

What is the result of the employees table has no records before the code executed?

A.
1 Sam

B.
4 Jack

C.
3 John
4 Jack

D.
1 Sam
3 John
4 Jack

Explanation:

AutoCommit is set to false. The two following statements will be within the same transaction.
stmt.executeUpdate(“insert into employees values(1,’Sam’)”);
stmt.executeUpdate(“insert into employees values(2,’Jane’)”);
These two statements are rolled-back through (the savepoint is ignored! the savepoint must be
specified (e.g.
conn.rollback(save1); ) in the rollback if you want to rollback to the savepoint):
conn.rollback() ;
The next two insert statements are executed fine. Their result will be in the output.



Leave a Reply 17

Your email address will not be published. Required fields are marked *


jalex

jalex

Answewr is D

jalex

jalex

Sorry Answer is not D, the correct answer is C because the rollback undo all the transactions, even if there is a savepoint.

Humberto Bañuelos Flores

Humberto Bañuelos Flores

public static void main(String[] args) {
String url = “jdbc:mysql://localhost:3306/employeedb?zeroDateTimeBehavior=convertToNull”;
String username = “userName”;
String password = “password”;
String query = “SELECT * FROM manager”;
try (Connection conn =
DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();) {
try {

conn.setAutoCommit(false);

stmt.executeUpdate(“INSERT INTO manager (first_name) VALUES(‘Sam’);”);
Savepoint save1 = conn.setSavepoint(“point1”);
stmt.executeUpdate(“INSERT INTO manager (first_name) VALUES(‘Jane’);”);
conn.rollback();
//conn.rollback(save1);
stmt.executeUpdate(“INSERT INTO manager (first_name) VALUES(‘Jonh’);”);
conn.setAutoCommit(true);
stmt.executeUpdate(“INSERT INTO manager (first_name) VALUES(‘Jack’);”);

ResultSet rs = stmt.executeQuery(“select * from manager”);
while (rs.next()) {
System.out.println(rs.getString(1) + ” ” + rs.getString(2));
}
} catch (Exception e) {
System.out.print(e.getMessage());
}
} catch (SQLException e) {
System.out.println(“SQL Exception: ” + e);
} // end of try-with-resources
}

delimiter $$

CREATE TABLE `manager` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(45) DEFAULT NULL,
`last_name` varchar(45) DEFAULT NULL,
`birth_date` date DEFAULT NULL,
`salary` double DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8$$

Google

Google

Usually posts some extremely fascinating stuff like this. If youre new to this site.

universal garage door remote

universal garage door remote

The data talked about within the write-up are a number of the ideal out there

Nursing Homes CT

Nursing Homes CT

one of our guests a short while ago recommended the following website

Play online games

Play online games

please go to the internet sites we comply with, like this a single, because it represents our picks in the web

controllare il mio sito

controllare il mio sito

just beneath, are numerous entirely not connected websites to ours, having said that, they’re surely really worth going over

sprint

sprint

that may be the end of this article. Right here you will find some web-sites that we think youll appreciate, just click the hyperlinks over

SEO services in Lahore

SEO services in Lahore

although web-sites we backlink to below are considerably not connected to ours, we feel they’re basically worth a go via, so have a look

make an app

make an app

here are some hyperlinks to websites that we link to because we think they may be really worth visiting

app maker free

app maker free

Sites of interest we have a link to

Divorce Law Firm for Men

Divorce Law Firm for Men

Sites of interest we’ve a link to

app maker free

app maker free

Sites of interest we’ve a link to

Tassendruck

Tassendruck

always a big fan of linking to bloggers that I appreciate but do not get a great deal of link love from

Fenster und Turen

Fenster und Turen

here are some links to web pages that we link to since we assume they may be really worth visiting