This project demonstrates how to use Java JDBC (Java Database Connectivity) to perform CRUD operations — Create, Read, Update, and Delete — on a Product table in a MySQL database.
It also implements transaction handling to maintain data integrity using setAutoCommit(false), commit(), and rollback().
To create a menu-driven Java program that performs all CRUD operations on a Product table in MySQL with proper transaction management and exception handling.
- JDBC Driver (
com.mysql.cj.jdbc.Driver) - Connection Management using
DriverManager PreparedStatementfor parameterized queries (Prevents SQL Injection)- Transaction Handling (
setAutoCommit(false),commit(),rollback()) - Menu-driven console application
- CRUD Operations (
INSERT,SELECT,UPDATE,DELETE)
Run the following commands in MySQL Workbench or Command Line:
CREATE DATABASE shopdb;
USE shopdb;
CREATE TABLE Product (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(50),
Price DOUBLE,
Quantity INT
);
INSERT INTO Product VALUES
(1, 'Laptop', 55000, 10),
(2, 'Smartphone', 25000, 20),
(3, 'Keyboard', 1200, 50);