Question

Choose a suitable language/technology/(ies) and implement connection to a database. Once connected to the database, your...

Choose a suitable language/technology/(ies) and implement connection to a database. Once connected to the database, your code should do the following: (a) Display multiple rows from a query result (b) Have a multi-statement transaction, where all statements succeed and the transaction commits. You can think of multiple sql statements that are planned to be run consecutively and both succeed. (c) Have a multi-statement transaction, where the earlier statements succeed and the later statement fails. In this case, the whole transaction must be rolled back. You can think of multiple sql statements that are planned to be run consecutively, but second one fails and therefore causes a rollback for your first statement.

Can this be done using JAVA/JDBC Connection. JDBC connection can be replaced.

Homework Answers

Answer #1

I have provided a basic overview of the solution. And for complete understanding, you can learn more about how the transaction works on servers.

For establishing a connection:

public Connection getConnection() throws SQLException {

Connection conn = null;

Properties connectionProps = new Properties();

connectionProps.put("user", this.userName);

connectionProps.put("password", this.password);

if (this.dbms.equals("mysql")) {

conn = DriverManager.getConnection(

   "jdbc:" + this.dbms + "://" +

   this.serverName +

   ":" + this.portNumber + "/",

   connectionProps);

} else if (this.dbms.equals("derby")) {

conn = DriverManager.getConnection(

   "jdbc:" + this.dbms + ":" +

   this.dbName +

   ";create=true",

   connectionProps);

}

System.out.println("Connected to database");

return conn;

}

How to extract multiple rows:

while(rs.next()){ //Retrieve by column name int id = rs.getInt("id"); int age = rs.getInt("age"); String first = rs.getString("first"); String last = rs.getString("last"); //Display values System.out.print("ID: " + id); System.out.print(", Age: " + age); System.out.print(", First: " + first); System.out.println(", Last: " + last); }

And for the 2nd and 3rd part the JDBC implements the concept of transaction and ACID Properties i.e Atomicity, Consistency, Isolation, Durability so this can be done as it has all the functionality

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...