0% found this document useful (0 votes)
5 views

Java Fintq II

Uploaded by

swarajya laxmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Fintq II

Uploaded by

swarajya laxmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Question - I managing financial transactions for a small bank

a Java program that connects to a MySQL database using JDBC and demonstrates the
use of Savepoints with multiple tables. Create two tables, accounts and
transactions. The accounts table should have the columns: account_id (INT),
account_name (VARCHAR), and balance (FLOAT). The transactions table should have the
columns: transaction_id (INT), account_id (INT), amount (FLOAT), and
transaction_type (VARCHAR). Perform multiple inserts into these tables, using
Savepoints to manage the transaction. Roll back to a Savepoint if an error occurs
during one of the inserts.
_______________________________________________________________________
Tasks:

1.Connect to the MySQL database using JDBC.


2.Create two tables:
accounts with columns:
account_id (INT, Primary Key)
account_name (VARCHAR)
balance (FLOAT)
transactions with columns:
transaction_id (INT, Primary Key)
account_id (INT, Foreign Key referencing accounts(account_id))
amount (FLOAT)
transaction_type (VARCHAR)
3.Insert multiple records into the accounts table.
4.Perform multiple inserts into the transactions table within a transaction.
5.Use savepoints to manage the transaction:
Set a savepoint before inserting records into the transactions table.
If an error occurs during one of the inserts, roll back to the
savepoint.
6.Ensure the program loads the JDBC driver, establishes a connection, and handles
exceptions appropriately.
7.Close all resources properly in the finally block.
_______________________________________________________________________

QUESTION II: managing the inventory of a retail store

program that connects to a MySQL database using JDBC, updates records in a table
named products, and demonstrates the use of Savepoints. The products table should
have the following columns: product_id (INT), name (VARCHAR), price (FLOAT), and
stock (INT). Ensure the program loads the JDBC driver, establishes a connection,
and handles exceptions appropriately. Use Savepoints to manage the transaction,
updating the price and stock of multiple products. Roll back to a Savepoint if an
error occurs during the update of one of the products.

Tasks:

1.Connect to the MySQL database using JDBC.


2.Create a table named products with the following columns:
product_id (INT, Primary Key)
name (VARCHAR)
price (FLOAT)
stock (INT)
3.Insert multiple records into the products table.
4.Use a transaction to update the price and stock of multiple products.
5.Use savepoints to manage the transaction. Set a savepoint before each update.
6.If an error occurs during the update of one of the products, roll back to the
last savepoint.
7.Ensure the program loads the JDBC driver, establishes a connection, and handles
exceptions appropriately.
8.Close all resources properly in the finally block.
_________________________________________________________________________
QUESTION -III

Write a Java program that connects to a MySQL database using JDBC, creates a table
named books, and deletes a record from it. The table books should have the
following columns: book_id (INT), title (VARCHAR), author (VARCHAR), and price
(FLOAT). Ensure the program loads the JDBC driver, establishes a connection, and
handles exceptions appropriately. Use a prepared statement to delete the book with
book_id = 2.

Write a Java program that performs the following tasks:

1.Connects to a MySQL database using JDBC.


2.Creates a table named books with the following columns:
book_id (INT)
title (VARCHAR)
author (VARCHAR)
price (FLOAT)
3.Inserts multiple records into the books table.
4.Uses a transaction to delete a book with book_id = 2. If an error occurs during
the deletion, the transaction should roll back to a savepoint before the deletion.
5.Ensure the program loads the JDBC driver, establishes a connection, and handles
exceptions appropriately.

You might also like