A Java-based Library Management System that allows users to register, login, add books (librarian role), view all books, and borrow books (member role). The system uses JDBC for database operations.
- User Registration and Login: Users can register with a username, password, and role (librarian or member) and login to the system.
- Librarian Functions:
- Add new books to the library.
- View all books available in the library.
- Member Functions:
- View all books available in the library.
- Borrow books from the library.
- Java Development Kit (JDK) 8 or higher
- JDBC driver for your database
- A database (e.g., MySQL, PostgreSQL, etc.)
- Create a database for the library system.
- Create the necessary tables:
CREATE TABLE Users ( user_id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, role VARCHAR(50) NOT NULL ); CREATE TABLE Books ( book_id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, author VARCHAR(255) NOT NULL, isbn VARCHAR(50) NOT NULL, available_copies INT NOT NULL, total_copies INT NOT NULL ); CREATE TABLE BorrowedBooks ( id INT AUTO_INCREMENT PRIMARY KEY, user_Id INT NOT NULL, book_Id INT NOT NULL, borrow_Date DATE NOT NULL, FOREIGN KEY (user_Id) REFERENCES Users(user_id), FOREIGN KEY (book_Id) REFERENCES Books(book_id) );
-
Update the
DatabaseConnection
class with your database connection details.public class DatabaseConnection { private static final String URL = "jdbc:your_database_url"; private static final String USERNAME = "your_database_username"; private static final String PASSWORD = "your_database_password"; public static Connection getConnection() throws SQLException { return DriverManager.getConnection(URL, USERNAME, PASSWORD); } }
-
Clone the repository:
git clone https://github.com/your-username/library-management-system.git cd library-management-system
-
Compile and run the application:
javac LibraryManagementSystem.java java LibraryManagementSystem
- Run the application.
- Select "Register" from the main menu.
- Enter a username, password, and role (librarian or member).
- Run the application.
- Select "Login" from the main menu.
- Enter your username and password.
- After logging in as a librarian, you can:
- Add new books to the library.
- View all books in the library.
- After logging in as a member, you can:
- View all books in the library.
- Borrow books from the library.
- Ensure you have your
DatabaseConnection
class properly set up for your specific database. - Modify the database schema creation SQL to match your database's syntax if necessary.
- Room for Improvement: There is potential to expand functionality by adding more CRUD operations (update and delete books, manage users, etc.).
- Input Sanitization: Input validation and sanitization can be enhanced to ensure robustness and security of the application.