0% found this document useful (0 votes)
3 views4 pages

Library_Management_LLD

The document outlines a Library Management System that includes features for book and user management, as well as a book borrowing system. It provides a MySQL database schema for storing books, users, and issued books, along with Java classes for database connection and data access operations. The main application allows users to add books, view all books, and register new users through a console interface.

Uploaded by

hello world
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Library_Management_LLD

The document outlines a Library Management System that includes features for book and user management, as well as a book borrowing system. It provides a MySQL database schema for storing books, users, and issued books, along with Java classes for database connection and data access operations. The main application allows users to add books, view all books, and register new users through a console interface.

Uploaded by

hello world
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Library Management System (LLD)

Features:
1. Book Management
- Add a book
- Remove a book
- View all books
2. User Management
- Register user
- Delete user
3. Book Borrowing System
- Issue a book to a user
- Return a book
- View issued books

Database Schema (MySQL):

CREATE DATABASE library_db;


USE library_db;

CREATE TABLE books (


id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
available BOOLEAN DEFAULT TRUE
);

CREATE TABLE users (


id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL
);

CREATE TABLE issued_books (


id INT PRIMARY KEY AUTO_INCREMENT,
book_id INT,
user_id INT,
issue_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (book_id) REFERENCES books(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);

Java Classes & JDBC Integration:


1. DatabaseConnection.java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {


private static final String URL = "jdbc:mysql://localhost:3306/library_db";
private static final String USER = "root";
private static final String PASSWORD = "your_password";

public static Connection getConnection() {


try {
return DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
}

2. BookDAO.java

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class BookDAO {


public void addBook(String title, String author) {
String query = "INSERT INTO books (title, author) VALUES (?, ?)";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.setString(1, title);
stmt.setString(2, author);
stmt.executeUpdate();
System.out.println("Book added successfully!");
} catch (SQLException e) {
e.printStackTrace();
}
}

public void viewBooks() {


String query = "SELECT * FROM books";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement stmt = conn.prepareStatement(query);
ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
System.out.println("ID: " + rs.getInt("id") +
", Title: " + rs.getString("title") +
", Author: " + rs.getString("author") +
", Available: " + rs.getBoolean("available"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

3. UserDAO.java

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserDAO {


public void registerUser(String name, String email) {
String query = "INSERT INTO users (name, email) VALUES (?, ?)";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.setString(1, name);
stmt.setString(2, email);
stmt.executeUpdate();
System.out.println("User registered successfully!");
} catch (SQLException e) {
e.printStackTrace();
}
}
}

4. LibraryApp.java (Main Application)

import java.util.Scanner;

public class LibraryApp {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BookDAO bookDAO = new BookDAO();
UserDAO userDAO = new UserDAO();

while (true) {
System.out.println("\n1. Add Book");
System.out.println("2. View Books");
System.out.println("3. Register User");
System.out.println("4. Exit");
System.out.print("Enter choice: ");

int choice = scanner.nextInt();


scanner.nextLine();

switch (choice) {
case 1:
System.out.print("Enter book title: ");
String title = scanner.nextLine();
System.out.print("Enter author name: ");
String author = scanner.nextLine();
bookDAO.addBook(title, author);
break;
case 2:
bookDAO.viewBooks();
break;
case 3:
System.out.print("Enter user name: ");
String name = scanner.nextLine();
System.out.print("Enter email: ");
String email = scanner.nextLine();
userDAO.registerUser(name, email);
break;
case 4:
System.out.println("Exiting...");
scanner.close();
System.exit(0);
default:
System.out.println("Invalid choice!");
}
}
}
}

You might also like