Java Swing | MySQL | JDBC
Welcome to Contact Book Manager — a robust and intuitive desktop application designed for effortlessly managing personal and professional contacts. Built using standard Java technologies, this project serves as a comprehensive, hands-on demonstration of how to architect a full-stack desktop application.
This application provides a full suite of CRUD (Create, Read, Update, Delete) operations within an intuitive GUI:
-
➕ Add New Contacts Quickly add new entries including name, phone number, and email.
-
👀 View Contacts Browse all contacts in a sortable, searchable table view.
-
✏️ Edit Contacts Click any row to auto-fill the form fields and update the contact.
-
🗑️ Delete Contacts Remove unnecessary entries with a confirmation prompt.
-
⚡ In-Memory Management Leverages Java’s
ArrayList
for fast, temporary in-memory storage synced with the database. -
💾 Persistent Storage Contact data is reliably stored and retrieved from a MySQL database using JDBC.
-
🖥️ User-Friendly Interface A clean, responsive GUI built with Java Swing for an easy and seamless user experience.
The project is organized into a modular, layered architecture:
- Java Swing handles all UI components like windows, buttons, forms, and tables.
- Contains business logic, coordinates between the UI and the database, and manages the in-memory contact list.
- JDBC is used for executing SQL operations.
- MySQL is the backend RDBMS for storing all contact records.
- Contact.java is a POJO that represents a contact entity (name, phone, email).
ContactBookManager/
├── src/
│ └── com/contactbook/
│ ├── model/
│ │ └── Contact.java
│ ├── database/
│ │ └── DatabaseManager.java
│ ├── service/
│ │ └── ContactService.java
│ └── gui/
│ └── ContactBookGUI.java
├── lib/
│ └── mysql-connector-j-9.3.0.jar
├── .project
├── .classpath
├── .settings/
└── ... (other IDE-generated files)
Run the following SQL script in MySQL Workbench or another client:
CREATE DATABASE IF NOT EXISTS connect_db;
USE connect_db;
CREATE TABLE IF NOT EXISTS contacts (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
phone VARCHAR(20),
email VARCHAR(255)
);
⚠️ Note: The application assumes the database and table already exist. It does not auto-create them.
Open DatabaseManager.java
and update your MySQL credentials:
private static final String JDBC_URL = "jdbc:mysql://localhost:3306/connect_db?useSSL=false&serverTimezone=UTC";
private static final String DB_USER = "your_username";
private static final String DB_PASSWORD = "your_password";
🔐 For production environments, avoid hardcoding credentials. Use environment variables or config files.
-
Clone/Download the project to your workspace.
-
Open Eclipse →
File > Import...
→Existing Projects into Workspace
→ Select root folder → Finish. -
Add MySQL Connector:
- Right-click project → New > Folder → Name it
lib
. - Paste
mysql-connector-j-9.3.0.jar
intolib/
. - Right-click project →
Build Path > Configure Build Path...
→ Libraries → Add JARs → Select the JAR.
- Right-click project → New > Folder → Name it
-
Clean and build the project:
Project > Clean... > Build Project
- Navigate to
ContactBookGUI.java
. - Right-click → Run As → Java Application.
-
Export as Runnable JAR:
File > Export... > Java > Runnable JAR file
- Choose launch config:
ContactBookGUI
- Library Handling: Package required libraries
- Export destination:
dist/ContactBookManager.jar
-
Run in terminal:
java -jar ContactBookManager.jar
For native Windows usage:
- Use Launch4j to wrap
.jar
as.exe
. - Optionally bundle a JRE for standalone deployment.
Contributions are welcome and appreciated! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-name
) - Commit your changes.
- Push to your fork.
- Open a pull request.
For bugs, enhancements, or feature ideas, feel free to open an issue.
- Java Swing for the GUI framework.
- MySQL for reliable data storage.
- JDBC for seamless Java-to-SQL integration.
- Eclipse IDE for project development.