This is a console-based Java application that demonstrates working with a MySQL database using JDBC. The project showcases CRUD operations, SQL queries, and table joins (JOIN) in practice.
- Add, view, update, and delete users (users) and orders (orders);
- Join tables to display orders along with their associated users;
- Automatically format user input (capitalize first letters of names);
- Automatically assign the current date to new orders;
- Validate user input for correctness.
- Java 17+
- JDBC
- MySQL
- Maven (for dependency management, e.g., mysql-connector-java)
- Console interface
CREATE DATABASE IF NOT EXISTS java_practice;
USE java_practice;CREATE TABLE users(
UserID INT PRIMARY KEY AUTO_INCREMENT,
LastName VARCHAR(50),
FirstName VARCHAR(50),
DateOfBirth DATE
);CREATE TABLE orders(
OrderID INT PRIMARY KEY AUTO_INCREMENT,
UserID INT,
Product VARCHAR(50),
Total_Price DECIMAL(10,2),
Order_Date DATE DEFAULT CURRENT_DATE,
FOREIGN KEY (UserID) REFERENCES users(UserID)
);- Add MySQL connector dependency in Maven:
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.1.0</version>
</dependency>- Set up your database connection in DatabaseConnection class.
- Run Main.java to start the application.
- Automatic capitalization of first letters in names
(Capitalize.capitalizeFirstLetter()); - Secure SQL queries using
PreparedStatement; - Input validation for ID, price, and date;
- Display orders with user information and order date;
- Support for deleting individual entries and cleaning entire tables.
Oleksii (GitHub)