The Bookstore Management System Java project enables customers to order books and admins to manage the orders. Our program provides a user-friendly graphical interface and connects to a MySQL database to handle all data storage and retrieval. Key features include viewing available books, placing and updating orders for customers, and managing delivery dates for the admin.
Introduction
To build this Java project, first, we created a framework for admin and customer with two buttons. The admin panel holds the customer’s name and the delivery date, which is added to the database to deliver the book with confirmation status. Next, the customer panel has the details like name, location, and book name for purchasing online.
The Bookstore Management System Java project can be beneficial to business people who want to sell their books online and maintain the book details in one place. This project works efficiently for ordering and delivering the books online.
Objectives
The Bookstore Management System Java Project has essentially the following objectives to achieve:
1. Create a GUI-based application to facilitate easy interaction for the users (customers and admin).
2. Allow customers to:
- View the list of available books from the bookstore.
- Place an order for a book by adding their details and the book information.
- Check their orders and update their own records.
3. Allow the admin to:
- View the list of books ordered by customers.
- Update the delivery date of a book ordered by a customer.
4. Connect to a MySQL database to:
- Store and retrieve the list of books and their details.
- Store and retrieve customer information and their orders.
5. Use a date picker for the admin to easily select a date when updating delivery dates.
6. Provide exception handling to manage any potential errors or exceptions that could arise during database operations.
Requirements
1. Java Development Kit (JDK) installed in your system to develop and run this Java program.
2. Java Swing for creating GUI.
3. MySQL Database: To store and manage book and order data. You need to have MySQL installed and a database set up with the correct tables and columns that align with the program.
4. JDBC Driver: It is a necessary tool to establish a connection between the Java application and the MySQL database. We have used “com.mysql.cj.jdbc.Driver” specifically.
5. Integrated Development Environment (IDE): An IDE like IntelliJ IDEA, Eclipse, or NetBeans is required to write and manage the code more efficiently.
6. JDateChooser Library is necessary for implementing the date picker in the application.
Source Code
package com.company; public class Main { public static void main(String[] args) { new BookStore(); } } package com.company; import javax.swing.*; import java.awt.* public class BookStore { private JButton CUSTOMERButton; private JButton ADMINButton; private JPanel mainPanel; JFrame mainF = new JFrame(); public BookStore() { mainF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainF.setContentPane(mainPanel); mainF.pack(); mainF.setLocationRelativeTo(null); mainF.setVisible(true); CUSTOMERButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new Customer(); } }); ADMINButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new Admin(); } }); } } package com.company; import com.toedter.calendar.JDateChooser; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.* import java.sql.*; import java.text.DateFormat; import java.util.Vector; public class Admin { private JTextField nameData; private JTable table1; private JButton UPDATERECORDButton; private JPanel adminPanel; private JPanel date; JFrame adminF = new JFrame(); JDateChooser dateChooser = new JDateChooser(); public Admin(){ adminF.setContentPane(adminPanel); adminF.pack(); adminF.setLocationRelativeTo(null); adminF.setVisible(true); date.add(dateChooser); tableData(); UPDATERECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try{ String deliDate = DateFormat.getDateInstance().format(dateChooser.getDate()); String sql = "UPDATE purchasedBooks " + "SET DELIVERY_DATE = '"+deliDate+"'"+ " WHERE NAME= '"+nameData.getText()+"'"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"Updated successfully"); }catch (Exception e2){ System.out.println(e2); } tableData(); } }); table1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { DefaultTableModel dm = (DefaultTableModel)table1.getModel(); int selectedRow = table1.getSelectedRow(); nameData.setText(dm.getValueAt(selectedRow,0).toString()); } }); } public void tableData() { try{ String a= "Select* from purchasedBooks"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(a); table1.setModel(buildTableModel(rs)); }catch (Exception ex1){ JOptionPane.showMessageDialog(null,ex1.getMessage()); } } public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException { ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames = new Vector<String>(); int columnCount = metaData.getColumnCount(); for (int column = 1; column <= columnCount; column++) { columnNames.add(metaData.getColumnName(column)); } // data of the table Vector<Vector<Object>> data = new Vector<Vector<Object>>(); while (rs.next()) { Vector<Object> vector = new Vector<Object>(); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { vector.add(rs.getObject(columnIndex)); } data.add(vector); } return new DefaultTableModel(data, columnNames); } } package com.company; //import com.toedter.calendar.JDateChooser; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.* import java.sql.*; import java.text.DateFormat; import java.util.Vector; public class Customer { private JTextField nameData; private JTextField locationData; private JTable table1; private JButton ADDRECORDButton; private JButton UPDATERECORDButton; private JPanel customerPanel; private JLabel price; private JLabel bookName; private JButton BOOKSAVAILABLEButton; private JComboBox type; private JPanel dateDeli; private JTextField quantity; JFrame custF = new JFrame(); public Customer(){ custF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); custF.setContentPane(customerPanel); custF.pack(); custF.setLocationRelativeTo(null); custF.setVisible(true); tableData(); ADDRECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(nameData.getText().equals("")|| locationData.getText().equals("")){ JOptionPane.showMessageDialog(null,"Please Fill All Fields to add Record."); }else{ try { String sql = "insert into purchasedBooks"+"(NAME,ADDRESS,BOOK_NAME,PRICE)"+"values (?,?,?,?)"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); statement.setString(1,nameData.getText()); statement.setString(2, locationData.getText()); statement.setString(3, bookName.getText()); statement.setString(4,price.getText()); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"ORDER PLACED SUCCESSFULLY!"); nameData.setText(""); locationData.setText(""); }catch (Exception ex){ JOptionPane.showMessageDialog(null,ex.getMessage()); } } } }); UPDATERECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { if (nameData.getText().equals("")) { JOptionPane.showMessageDialog(null,"Please Enter Name to check"); }else{ String sql = "SELECT* from purchasedBooks WHERE NAME= '" + nameData.getText()+"'"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern", "root", "root"); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(sql); if(!rs.next()) JOptionPane.showMessageDialog(null,"NO CUSTOMER FOUND"); else { ResultSet rs1 = statement.executeQuery(sql); table1.setModel(buildTableModel(rs1)); } } }catch (Exception e2){ JOptionPane.showMessageDialog(null,"NO CUSTOMER FOUND"); } } }); table1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { DefaultTableModel dm = (DefaultTableModel)table1.getModel(); int selectedRow = table1.getSelectedRow(); bookName.setText(dm.getValueAt(selectedRow,0).toString()); price.setText(dm.getValueAt(selectedRow,1).toString()); } }); BOOKSAVAILABLEButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tableData(); } }); } public void tableData() { try{ String a= "Select* from booksPresent"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(a); table1.setModel(buildTableModel(rs)); }catch (Exception ex1){ JOptionPane.showMessageDialog(null,ex1.getMessage()); } } public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException { ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames = new Vector<String>(); int columnCount = metaData.getColumnCount(); for (int column = 1; column <= columnCount; column++) { columnNames.add(metaData.getColumnName(column)); } // data of the table Vector<Vector<Object>> data = new Vector<Vector<Object>>(); while (rs.next()) { Vector<Object> vector = new Vector<Object>(); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { vector.add(rs.getObject(columnIndex)); } data.add(vector); } return new DefaultTableModel(data, columnNames); } }
Explanation of the Code
The Online Book Store System Java Project code can be broken down into two sections. One involves creating the GUI, and the other is the retrieval of information
GUI (Graphical User Interface):
1. The BookStore class is the main interface for the application. It provides two buttons: “CUSTOMER” and “ADMIN”. If the user clicks on “CUSTOMER”, it initiates the Customer interface; similarly, if the user clicks on “ADMIN”, it initiates the Admin interface.
2. The Customer interface allows users to add their purchase records. It contains fields for the customer’s name, location, and details about the book they are buying. It also provides the buttons “ADD RECORD” and “UPDATE RECORD”.
3. The Admin interface displays a table of all the books purchased, allowing the admin to update the delivery date for a particular purchase record. It also provides a button “UPDATE RECORD”.
Moving to the Functions:
1. Main class launches the application by creating a new instance of the BookStore class.
2. BookStore class creates the initial window of the application, which consists of two buttons – one for Customer and one for Admin. Depending on which button is clicked, a new instance of the corresponding class (Customer or Admin) is created and displayed.
3. Admin class allows the admin to update the delivery date of purchased books. It features a table showing details of purchased books. The admin can select a book from the table, choose a date using a date picker, and click the update button to change the delivery date of the selected book in the database.
4. Customer class allows customers to interact with the bookstore. It has options to add a record (order a book), view available books, and update their own records. Customers can see the list of books available in the store in a table. After selecting a book, they can place an order by filling out their details and clicking the “Add Record” button. They can also update their records or check their orders by entering their name and clicking the “Update Record” button.
Output
Main Interface
Admin Interface
Customer Interface
Conclusion
Hence we have successfully developed the Bookstore Management System Java Project that helps to manage a book store online where people can purchase books with Swing used for GUI. It contains the admin page and customer, where the admin can update the details of books available in the store, and customers can see and buy the books. This is a very efficient way to store & get access to the books available & easily place an order & get a scheduled delivery date.

As a passionate Java developer with over 10 years of experience, I live and breathe Java programming. I have a deep understanding of Java core concepts such as object-oriented programming, multithreading, exception handling, and Java collections. I am proficient in using Java libraries, frameworks, and tools and can write clean, efficient, and maintainable Java code. I can design and implement RESTful APIs, work with databases, and integrate with various third-party services.
0 Comments