Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Library Management System

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.


πŸ—‚ Table of Contents


Project Overview

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.


Features

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

Technologies Used

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

OOP Concepts Demonstrated

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

Project Structure

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

Database Setup

  1. Start your MySQL 8 server.
  2. Open a MySQL client (MySQL Workbench, DBeaver, or the CLI).
  3. Run the SQL script:
    SOURCE /path/to/LibraryManagementSystem/database/library.sql;
    Or paste the contents of database/library.sql directly.

This will:

  • Create the library_db database.
  • Create the books, users, and borrow_transactions tables with foreign keys.
  • Insert 10 sample books, 10 sample users, and 10 sample transactions.

Installation & Running

Prerequisites

  • Java 17+ (java -version)
  • Maven 3.8+ (mvn -version)
  • MySQL 8+ running locally

Step 1 – Configure database credentials

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";

Step 2 – Build

cd LibraryManagementSystem
mvn clean package

This produces a runnable fat JAR at:

target/LibraryManagementSystem-1.0.0-runnable.jar

Step 3 – Run

java -jar target/LibraryManagementSystem-1.0.0-runnable.jar

Console Menu Reference

╔══════════════════════════════════════╗
β•‘     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
================================

Book Management Sub-Menu

 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

User Management Sub-Menu

 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

Reports Sub-Menu

 1. All Books
 2. Available Books
 3. Borrowed Books
 4. Full Borrow History
 5. User Borrow History   β†’ prompts for user ID
 6. Back

UML Class Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   <<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 Section

Screenshots will be added once the application is running. Run java -jar target/LibraryManagementSystem-1.0.0-runnable.jar and capture the menus.


Future Enhancements

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

License

This project is released for educational purposes. Feel free to use and extend it.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages