A complete, production-ready Library Management System built with Java 17, MySQL 8, JDBC, and Maven following the DAO design pattern and core Object-Oriented Programming principles.
- Project Overview
- Features
- Technologies Used
- OOP Concepts Demonstrated
- Project Structure
- Database Setup
- Installation & Running
- Console Menu Reference
- UML Class Diagram
- Future Enhancements
This system manages the day-to-day operations of a library, including cataloguing books, registering members, issuing and returning books, and generating reports. All data is persisted to a MySQL database, accessed through a clean DAO layer.
| Category | Feature |
|---|---|
| Books | Add, Update, Delete, Search (by ID / Title / Author / ISBN / Genre), View All / Available / Borrowed |
| Users | Register, Update, Delete, Search (by ID / Name), View All |
| Transactions | Borrow book (with availability check), Return book (atomically) |
| Reports | All books, Available books, Borrowed books, Full borrow history, Per-user borrow history |
| Safety | Duplicate ISBN prevention, Borrowing unavailable books blocked, Custom exceptions, Input validation |
| DB | Singleton connection, PreparedStatement everywhere, Atomic borrow/return via JDBC transactions |
| Technology | Version | Purpose |
|---|---|---|
| Java | 17 | Core language |
| MySQL | 8+ | Relational database |
| JDBC | β | Database connectivity |
| Maven | 3.8+ | Build & dependency management |
| mysql-connector-j | 8.3.0 | MySQL JDBC driver |
| maven-shade-plugin | 3.5.1 | Executable fat JAR |
| Concept | Where |
|---|---|
| Encapsulation | All model fields are private with getters/setters |
| Abstraction | Person abstract class; BookDAO, UserDAO, TransactionDAO interfaces |
| Inheritance | User extends Person, Librarian extends User |
| Polymorphism | displayDetails() overridden in User and Librarian; DAO interface / impl separation |
| Exception Handling | Five custom checked exceptions; try-catch at service and Main layers |
| Singleton Pattern | DatabaseConnection |
| DAO Pattern | Interface + Impl for Book, User, Transaction |
| Facade Pattern | LibraryService hides all DAO complexity from Main |
LibraryManagementSystem/
βββ pom.xml
βββ README.md
βββ database/
β βββ library.sql β Schema + sample data
βββ src/main/java/com/library/
βββ Main.java β Console menu entry point
βββ config/
β βββ DatabaseConnection.java β Singleton JDBC manager
βββ model/
β βββ Person.java β Abstract base class
β βββ User.java β Library member
β βββ Librarian.java β Staff (extends User)
β βββ Book.java β Catalogue entry
β βββ BorrowTransaction.java β Borrow/return record
βββ dao/
β βββ BookDAO.java β Book CRUD interface
β βββ UserDAO.java β User CRUD interface
β βββ TransactionDAO.java β Transaction interface
βββ daoimpl/
β βββ BookDAOImpl.java β JDBC book impl
β βββ UserDAOImpl.java β JDBC user impl
β βββ TransactionDAOImpl.java β JDBC transaction impl
βββ service/
β βββ LibraryService.java β Business logic facade
βββ util/
β βββ InputValidator.java β Validation helpers
βββ exception/
βββ BookNotFoundException.java
βββ UserNotFoundException.java
βββ BookUnavailableException.java
βββ DuplicateBookException.java
βββ DatabaseConnectionException.java
- Start your MySQL 8 server.
- Open a MySQL client (MySQL Workbench, DBeaver, or the CLI).
- Run the SQL script:
Or paste the contents of
SOURCE /path/to/LibraryManagementSystem/database/library.sql;
database/library.sqldirectly.
This will:
- Create the
library_dbdatabase. - Create the
books,users, andborrow_transactionstables with foreign keys. - Insert 10 sample books, 10 sample users, and 10 sample transactions.
- Java 17+ (
java -version) - Maven 3.8+ (
mvn -version) - MySQL 8+ running locally
Open src/main/java/com/library/config/DatabaseConnection.java and update:
private static final String URL = "jdbc:mysql://localhost:3306/library_db...";
private static final String USERNAME = "your_mysql_username";
private static final String PASSWORD = "your_mysql_password";cd LibraryManagementSystem
mvn clean packageThis produces a runnable fat JAR at:
target/LibraryManagementSystem-1.0.0-runnable.jar
java -jar target/LibraryManagementSystem-1.0.0-runnable.jarββββββββββββββββββββββββββββββββββββββββ
β LIBRARY MANAGEMENT SYSTEM β
ββββββββββββββββββββββββββββββββββββββββ
========== MAIN MENU ==========
1. Book Management
2. User Management
3. Borrow Book
4. Return Book
5. Search Book
6. Search User
7. Reports
8. Exit
================================
1. Add Book β prompts for title, author, ISBN, genre, status
2. Update Book β prompts for book ID + new values
3. Delete Book β prompts for book ID + confirmation
4. View All Books β tabular display of every book
5. Back
1. Register User β prompts for name, email, phone
2. Update User β prompts for user ID + new values
3. Delete User β prompts for user ID + confirmation
4. View All Users β tabular display of every user
5. Back
1. All Books
2. Available Books
3. Borrowed Books
4. Full Borrow History
5. User Borrow History β prompts for user ID
6. Back
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β <<abstract>> β
β Person β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β - userId: int β
β - name: String β
β - email: String β
β - phone: String β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β + getters/setters β
β + {abstract} displayDetails(): void β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β extends
βββββββββββββββ΄ββββββββββββββ
β β
βββββββββββΌβββββββββββ βββββββββββΌβββββββββββββββββββ
β User β β Librarian β
ββββββββββββββββββββββ βββββββββββββββββββββββββββββββ
β β β - staffId: String β
ββββββββββββββββββββββ βββββββββββββββββββββββββββββββ
β + displayDetails() β β + addBook(String): void β
ββββββββββββββββββββββ β + removeBook(String): void β
β + updateBook(String): void β
β + manageUsers(String): void β
β + displayDetails(): void β
βββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββ
β Book β
βββββββββββββββββββββββββββββββββββββ
β - bookId: int β
β - title: String β
β - author: String β
β - isbn: String β
β - genre: String β
β - status: String β
βββββββββββββββββββββββββββββββββββββ
β + constructors β
β + getters/setters β
β + displayBook(): void β
βββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββ
β BorrowTransaction β
βββββββββββββββββββββββββββββββββββββ
β - transactionId: int β
β - userId: int β
β - bookId: int β
β - borrowDate: LocalDate β
β - returnDate: LocalDate β
βββββββββββββββββββββββββββββββββββββ
β + constructors β
β + getters/setters β
β + displayTransaction(): void β
βββββββββββββββββββββββββββββββββββββ
<<interface>> BookDAO
+ addBook(Book)
+ updateBook(Book)
+ deleteBook(int)
+ searchBookById(int)
+ searchBookByTitle(String)
+ searchBookByAuthor(String)
+ searchBookByISBN(String)
+ searchBookByGenre(String)
+ getAllBooks()
+ getAvailableBooks()
+ getBorrowedBooks()
β² implements
BookDAOImpl (JDBC)
<<interface>> UserDAO
+ registerUser(User)
+ updateUser(User)
+ deleteUser(int)
+ searchUserById(int)
+ searchUserByName(String)
+ getAllUsers()
β² implements
UserDAOImpl (JDBC)
<<interface>> TransactionDAO
+ borrowBook(int, int)
+ returnBook(int)
+ getBorrowHistory()
+ getUserBorrowHistory(int)
β² implements
TransactionDAOImpl (JDBC)
LibraryService ββusesβββΊ BookDAO
ββusesβββΊ UserDAO
ββusesβββΊ TransactionDAO
Main ββusesβββΊ LibraryService
ββusesβββΊ DatabaseConnection (Singleton)
Screenshots will be added once the application is running. Run
java -jar target/LibraryManagementSystem-1.0.0-runnable.jarand capture the menus.
| Enhancement | Description |
|---|---|
| GUI | JavaFX or Swing front-end to replace the console |
| Web API | Spring Boot REST layer exposing the service |
| Fine System | Automatic fine calculation for overdue books |
| Authentication | Librarian login with hashed passwords |
| Pagination | Paginated book / user listing for large datasets |
| Connection Pool | HikariCP connection pooling for multi-threaded use |
| Unit Tests | JUnit 5 + Mockito test suite |
| Logging | SLF4J + Logback replacing System.out |
| Docker | Containerised MySQL + app with docker-compose |
| Export | PDF / CSV report export via iText / Apache POI |
This project is released for educational purposes. Feel free to use and extend it.