

{"id":113561,"date":"2023-04-03T09:00:08","date_gmt":"2023-04-03T03:30:08","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=113561"},"modified":"2026-06-01T14:26:51","modified_gmt":"2026-06-01T08:56:51","slug":"java-library-management","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/java-library-management\/","title":{"rendered":"Java Library Management \u2013 The Backbone of Any Successful Library"},"content":{"rendered":"<p>In this project, we will learn how to create a Library Management System using Java programming language and Swing GUI library for the user interface. The system comprises three main tables: Books, Borrowers, and Checkouts.<\/p>\n<p>The system uses SQLite database to store and manage the data. Each table will have an input panel, which allows the user to input and update data.<\/p>\n<p>With this system, users can easily manage and organize the library&#8217;s collection, track the borrowing history of books, and manage borrower information.<\/p>\n<p>By the end of this project, you will have a good understanding of how to build a fully functional Library Management System using Java and SQLite databases.<\/p>\n<h3>About Java Library Management System<\/h3>\n<p>The objective of this project is to guide you through the process of developing a Library Management System using Java and Swing for the user interface. The system will consist of three tables &#8211; Books, Borrowers, and Checkouts &#8211; and will utilize SQLite as the database management system.<\/p>\n<p>Additionally, the project will cover the creation of input panels for each table to facilitate data entry and manipulation within the system.<\/p>\n<h3>Prerequisites for Library Management System using Java<\/h3>\n<p>It is necessary to be familiar with Java Swing for developing graphical user interfaces (GUIs) and have knowledge of databases and SQL queries. While any Java integrated development environment (IDE) can be used, Eclipse is recommended, and utilizing the WindowBuilder plugin can simplify GUI development by allowing for drag-and-drop GUI component placement and automatic code generation.<\/p>\n<h3>Download Java Library Management System<\/h3>\n<p>Please download the source code of Java Library Management System project from the following link:<a href=\"https:\/\/drive.google.com\/file\/d\/1lkDjOQkVIXbJ3k0vHZ3m8Xm66bpdxjXd\/view?usp=drive_link\"> <strong>Java Library Management System Project Code<\/strong><\/a><\/p>\n<h3>Steps to Create Library Management System using Java<\/h3>\n<p>Following are the steps for developing the Java Library Management System Project:<\/p>\n<h4>Step 1: Creating the required classes in the project<\/h4>\n<ol>\n<li>Open Eclipse and go to &#8220;File&#8221; &gt; &#8220;New&#8221; &gt; &#8220;Java Project&#8221;.<\/li>\n<li>Name your project,&#8221;Library Management System&#8221;.<\/li>\n<li>Right-click on the project and select &#8220;New&#8221; &gt; &#8220;Class&#8221; to create a new class.<\/li>\n<li>Name the class &#8220;LibraryManagement&#8221; to represent the main class that will handle the system&#8217;s operations.<\/li>\n<li>Repeat step 3 and 4 to create another class named &#8220;Database&#8221; which will manage the system&#8217;s data storage and retrieval.<\/li>\n<\/ol>\n<h4>Step 2: Adding Sqlite into our project<\/h4>\n<p>Note: Before proceeding, ensure you have the SQLite JAR file downloaded and stored in a local location. If not, it can be obtained from <a href=\"https:\/\/mvnrepository.com\/artifact\/org.xerial\/sqlite-jdbc\">MavenRepository<\/a><\/p>\n<ol>\n<li>Go to the Project Explorer in Eclipse.<\/li>\n<li>Select the project name by right-clicking on it and choose &#8220;Properties&#8221;.<\/li>\n<li>In the Properties window, navigate to &#8220;Java Build Path&#8221; and then click the &#8220;Libraries&#8221; tab.<\/li>\n<li>Hit the &#8220;Add External JARs&#8221; button, and locate the SQLite JAR file.<\/li>\n<li>Select the JAR file and press &#8220;Open&#8221;.<\/li>\n<li>Click &#8220;OK&#8221; to close the Properties window.<\/li>\n<\/ol>\n<h4>Step 2: Adding Sqlite<\/h4>\n<p>(<a href=\"https:\/\/mvnrepository.com\/artifact\/org.xerial\/sqlite-jdbc\">https:\/\/mvnrepository.com\/artifact\/org.xerial\/sqlite-jdbc<\/a>).<\/p>\n<ol>\n<li>Select the project name by right-clicking on it and choose &#8220;Properties&#8221;.<\/li>\n<li>In the Properties window, navigate to &#8220;Java Build Path&#8221; and then click the &#8220;Libraries&#8221; tab.<\/li>\n<li>Click &#8220;Add External JARs&#8221; button, and select SQLite JAR file.<\/li>\n<li>Select JAR file and click &#8220;Open&#8221;.<\/li>\n<li>Click &#8220;OK&#8221;.<\/li>\n<\/ol>\n<h4>Step 3: Implementing the Database class<\/h4>\n<p>Here\u2019s the complete code for the database class:<\/p>\n<h4>Step 3: Creating the Database class<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.training.dataFlair;\r\nimport javax.swing.table.DefaultTableModel;\r\nimport java.sql.*;\r\npublic class Database {\r\n\/\/\t\tdeclaring the database path\r\n   private final static String DB_URL = \"jdbc:sqlite:library.db\";\r\n\/\/\t Method to add the book into the database\r\n   static void addBook(String title, String author, String genre, String publicationDate, String isbn, boolean available) throws SQLException {\r\n  \r\n  \r\n   String insertBookQuery = \"INSERT INTO books (title, author, genre, publication_date, isbn, available) VALUES (?, ?, ?, ?, ?, ?)\";\r\n   Connection conn = DriverManager.getConnection(DB_URL);\r\n   PreparedStatement insertBookStmt = conn.prepareStatement(insertBookQuery);\r\n   insertBookStmt.setString(1, title);\r\n   insertBookStmt.setString(2, author);\r\n   insertBookStmt.setString(3, genre);\r\n   insertBookStmt.setString(4, publicationDate);\r\n   insertBookStmt.setString(5, isbn);\r\n   insertBookStmt.setBoolean(6, available);\r\n   insertBookStmt.executeUpdate();\r\n  \r\n   insertBookStmt.close();\r\n   conn.close();\r\n  \r\n   }\r\n\/\/\t Method to add the borrower into the database\r\n   static void addBorrower(String name, String email, String phone, String address)throws SQLException {\r\n  \r\n    \r\n   String query = \"INSERT INTO borrowers (name,email,phone,address) VALUES (?, ?, ?, ?)\";\r\n   Connection conn = DriverManager.getConnection(DB_URL);\r\n   PreparedStatement insertBorrower = conn.prepareStatement(query);\r\n   insertBorrower.setString(1, name);\r\n   insertBorrower.setString(2, email);\r\n   insertBorrower.setString(3, phone);\r\n   insertBorrower.setString(4, address);\r\n   insertBorrower.executeUpdate();\r\n  \r\n   insertBorrower.close();\r\n   conn.close();\r\n  \r\n   }\r\n  \r\n\/\/\t Method to add checkout into the database\r\n   static void addCheckout(String bookID,String borrowerID,String coutdate,String duedate ,String returnDate)throws SQLException {\r\n  \r\n    \r\n   String query = \"INSERT INTO checkouts(book_id,borrower_id,checkout_date,due_date,return_date) VALUES (?, ?, ?, ?, ?)\";\r\n  \r\n   Connection conn = DriverManager.getConnection(DB_URL);\r\n   PreparedStatement insetBorrower = conn.prepareStatement(query);\r\n   insetBorrower.setInt(1, Integer.valueOf(bookID));\r\n   insetBorrower.setInt(2, Integer.valueOf(borrowerID));\r\n   insetBorrower.setString(3,coutdate);\r\n   insetBorrower.setString(4, duedate);\r\n   insetBorrower.setString(5, returnDate);\r\n   insetBorrower.executeUpdate();\r\n  \r\n   insetBorrower.close();\r\n   conn.close();\r\n  \r\n   }\r\n  \r\n\/\/\t Method to create database with the three columns books,borrowers and checkouts\r\nstatic void createDatabase() {\r\ntry (Connection conn = DriverManager.getConnection(DB_URL);\r\nStatement stmt = conn.createStatement()) {\r\nString createBooksTable = \"CREATE TABLE IF NOT EXISTS books (\" +\r\n\"id INTEGER PRIMARY KEY AUTOINCREMENT, \" +\r\n\"title TEXT NOT NULL, \" +\r\n\"author TEXT NOT NULL, \" +\r\n\"genre TEXT, \" +\r\n\"publication_date TEXT, \" +\r\n\"isbn TEXT, \" +\r\n\"available INTEGER DEFAULT 1\" +\r\n\")\";\r\nstmt.executeUpdate(createBooksTable);\r\nString createBorrowersTable = \"CREATE TABLE IF NOT EXISTS borrowers (\" +\r\n\"id INTEGER PRIMARY KEY AUTOINCREMENT, \" +\r\n\"name TEXT NOT NULL, \" +\r\n\"email TEXT UNIQUE NOT NULL, \" +\r\n\"phone TEXT, \" +\r\n\"address TEXT\" +\r\n\")\";\r\nstmt.executeUpdate(createBorrowersTable);\r\nString createCheckoutsTable = \"CREATE TABLE IF NOT EXISTS checkouts (\" +\r\n\"id INTEGER PRIMARY KEY AUTOINCREMENT, \" +\r\n\"book_id INTEGER NOT NULL, \" +\r\n\"borrower_id INTEGER NOT NULL, \" +\r\n\"checkout_date TEXT NOT NULL, \" +\r\n\"due_date TEXT NOT NULL, \" +\r\n\"return_date TEXT, \" +\r\n\"FOREIGN KEY (book_id) REFERENCES books(id), \" +\r\n\"FOREIGN KEY (borrower_id) REFERENCES borrowers(id)\" +\r\n\")\";\r\nstmt.executeUpdate(createCheckoutsTable);\r\nstmt.close();\r\nconn.close();\r\n} catch (SQLException e) {\r\ne.printStackTrace();\r\n}\r\n}\r\n\/\/ Method to delete the entry from the database given the id and the table name\r\nstatic void delete(String tableName,String id) throws SQLException {\r\n  String query = \"DELETE FROM \"+tableName+\" WHERE id = \"+id+\";\";\r\nConnection conn = DriverManager.getConnection(DB_URL);\r\nStatement delete = conn.createStatement();\r\ndelete.execute(query);\r\ndelete.close();\r\nconn.close();\r\n  }\r\n\/\/ Method to refresh the tables with the updated data from the database\r\nstatic void refreshTables(DefaultTableModel bookModel, DefaultTableModel borrowerModel, DefaultTableModel checkoutModel) {\r\nbookModel.setRowCount(0);\r\nborrowerModel.setRowCount(0);\r\ncheckoutModel.setRowCount(0);\r\ntry (Connection conn = DriverManager.getConnection(DB_URL)) {\r\nString selectBooksQuery = \"SELECT id, title, author, genre, publication_date, isbn, available FROM books\";\r\nPreparedStatement selectBooksStmt = conn.prepareStatement(selectBooksQuery);\r\nResultSet bookResults = selectBooksStmt.executeQuery();\r\nwhile (bookResults.next()) {\r\nObject[] bookData = {\r\nbookResults.getInt(\"id\"),\r\nbookResults.getString(\"title\"),\r\nbookResults.getString(\"author\"),\r\nbookResults.getString(\"genre\"),\r\nbookResults.getString(\"publication_date\"),\r\nbookResults.getString(\"isbn\"),\r\nbookResults.getBoolean(\"available\")\r\n};\r\nbookModel.addRow(bookData);\r\n}\r\nString selectBorrowersQuery = \"SELECT id, name, email, phone, address FROM borrowers\";\r\nPreparedStatement selectBorrowersStmt = conn.prepareStatement(selectBorrowersQuery);\r\nResultSet borrowerResults = selectBorrowersStmt.executeQuery();\r\nwhile (borrowerResults.next()) {\r\nObject[] borrowerData = {\r\nborrowerResults.getInt(\"id\"),\r\nborrowerResults.getString(\"name\"),\r\nborrowerResults.getString(\"email\"),\r\nborrowerResults.getString(\"phone\"),\r\nborrowerResults.getString(\"address\")\r\n};\r\nborrowerModel.addRow(borrowerData);\r\n}\r\nString selectCheckoutsQuery = \"SELECT id, book_id, borrower_id, checkout_date, due_date, return_date FROM checkouts\";\r\nPreparedStatement selectCheckoutsStmt = conn.prepareStatement(selectCheckoutsQuery);\r\nResultSet checkoutResults = selectCheckoutsStmt.executeQuery();\r\nwhile (checkoutResults.next()) {\r\nObject[] checkoutData = {\r\ncheckoutResults.getInt(\"id\"),\r\ncheckoutResults.getInt(\"book_id\"),\r\ncheckoutResults.getInt(\"borrower_id\"),\r\ncheckoutResults.getString(\"checkout_date\"),\r\ncheckoutResults.getString(\"due_date\"),\r\ncheckoutResults.getString(\"return_date\")\r\n};\r\ncheckoutModel.addRow(checkoutData);\r\n}\r\n} catch (SQLException e) {\r\ne.printStackTrace();\r\n}\r\n}\r\n}<\/pre>\n<ul>\n<li><strong>addBook<\/strong>(String title, String author, String genre, String publicationDate, String isbn, boolean available) &#8211; This method takes book information as input parameters and adds a new book to the database table &#8216;books&#8217;. It uses a prepared statement to avoid SQL injection.<\/li>\n<li><strong>addBorrower<\/strong>(String name, String email, String phone, String address) &#8211; This method takes borrower information as input parameters and adds a new borrower to the database table &#8216;borrowers&#8217;. It uses a prepared statement.<\/li>\n<li><strong>addCheckout<\/strong>(String bookID, String borrowerID, String coutdate, String duedate, String returnDate) &#8211; This method takes checkout information as input parameters and adds a new checkout to the database table &#8216;checkouts&#8217;. It uses a prepared statement .<\/li>\n<li><strong>createDatabase()<\/strong> &#8211; This method creates the database if it doesn&#8217;t exist and creates three tables, &#8216;books&#8217;, &#8216;borrowers&#8217;, and &#8216;checkouts&#8217;, if they don&#8217;t exist. The &#8216;books&#8217; table contains information about the books, the &#8216;borrowers&#8217; table contains information about the borrowers, and the &#8216;checkouts&#8217; table contains information about the book checkouts.<\/li>\n<li><strong>delete(<\/strong>String tableName, String id) &#8211; This method takes table name and id as input parameters and deletes the corresponding entry from the table.<\/li>\n<li><strong>refreshTables(<\/strong>DefaultTableModel bookModel, DefaultTableModel borrowerModel, DefaultTableModel checkoutModel) &#8211; This method refreshes the book, borrower, and checkout tables with the updated data from the database. It first clears the existing data from the tables and then fetches the updated data from the database using SQL queries. It then adds the fetched data to the corresponding tables.<\/li>\n<\/ul>\n<h4>Step 4:Implementing the LibraryManagement class<\/h4>\n<p>Here\u2019s the complete code for the LibraryManagement class:<br \/>\npackage com.training.dataFlair;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.awt.BorderLayout;\r\nimport java.awt.Color;\r\nimport java.awt.GridLayout;\r\nimport java.awt.TextField;\r\nimport java.awt.event.ActionEvent;\r\nimport java.awt.event.ActionListener;\r\nimport java.sql.SQLException;\r\nimport java.text.DateFormat;\r\nimport java.text.SimpleDateFormat;\r\n\r\nimport javax.swing.JButton;\r\nimport javax.swing.JCheckBox;\r\nimport javax.swing.JFormattedTextField;\r\nimport javax.swing.JFrame;\r\nimport javax.swing.JLabel;\r\nimport javax.swing.JOptionPane;\r\nimport javax.swing.JPanel;\r\nimport javax.swing.JScrollPane;\r\nimport javax.swing.JTabbedPane;\r\nimport javax.swing.JTable;\r\nimport javax.swing.JTextField;\r\nimport javax.swing.RepaintManager;\r\nimport javax.swing.event.ChangeEvent;\r\nimport javax.swing.event.ChangeListener;\r\nimport javax.swing.table.DefaultTableModel;\r\nimport javax.swing.border.MatteBorder;\r\n\r\npublic class LibraryManagement extends JFrame {\r\n   \tprivate final String[] bookColumns = {\"ID\", \"Title\", \"Author\", \"Genre\", \"Publication Date\", \"ISBN\", \"Available\"};\r\n      private final String[] borrowerColumns = {\"ID\", \"Name\", \"Email\", \"Phone\", \"Address\"};\r\n      private final String[] checkoutColumns = {\"ID\", \"Book ID\", \"Borrower ID\", \"Checkout Date\", \"Due Date\", \"Return Date\"};\r\n\r\n      private JTabbedPane tabbedPane;\r\n      private JTable bookTable;\r\n      private JTable borrowerTable;\r\n      private JTable checkoutTable;\r\n\r\n      \/\/ Add UI components\r\n      private JTextField booktitleField;\r\n      private JTextField nameField;\r\n      private JTextField emailField;\r\n      private JTextField phoneField;\r\n      private JTextField addresssField;\r\n      private JTextField authorField;\r\n      private JTextField genreField;\r\n      private JTextField pubDateField;\r\n      private JTextField isbnField;\r\n      private JCheckBox availableField;\r\n    private JTextField bookIDField;\r\n    private JTextField borrowerIDField;\r\n    private JTextField checkoutDateField;\r\n    private JTextField dueDateField;\r\n    private JTextField returnDateField;\r\n    private JTextField deleteBookField;\r\n    private JTextField deleteBorrowerField;\r\n    private JTextField deletecheckoutField;\r\n      public LibraryManagement() {\r\n      \tgetContentPane().setBackground(new Color(221, 161, 94));\r\n\r\n          Database.createDatabase();\r\n\r\n          DefaultTableModel bookModel = new DefaultTableModel(bookColumns, 0);\r\n          bookTable = new JTable(bookModel);\r\n\r\n          DefaultTableModel borrowerModel = new DefaultTableModel(borrowerColumns, 0);\r\n          borrowerTable = new JTable(borrowerModel);\r\n\r\n          DefaultTableModel checkoutModel = new DefaultTableModel(checkoutColumns, 0);\r\n          checkoutTable = new JTable(checkoutModel);\r\n\r\n          Database.refreshTables(bookModel,borrowerModel,checkoutModel);\r\n\r\n          tabbedPane = new JTabbedPane();\r\n          tabbedPane.addTab(\"Books\", new JScrollPane(bookTable));\r\n          tabbedPane.addTab(\"Borrowers\", new JScrollPane(borrowerTable));\r\n          tabbedPane.addTab(\"Checkouts\", new JScrollPane(checkoutTable));\r\n\r\n          \/\/ Book input Panel\r\n          booktitleField = new JTextField(20);\r\n          authorField = new JTextField(20);\r\n          genreField = new JTextField(20);\r\n          pubDateField = new JTextField(10);\r\n          isbnField = new JTextField(13);\r\n          availableField = new JCheckBox(\"Available\");\r\n          deleteBookField = new JTextField();\r\n          JButton addBookButton = new JButton(\"Add Book\");\r\n          addBookButton.addActionListener(new ActionListener() {\r\n              @Override\r\n              public void actionPerformed(ActionEvent e) {\r\n                 try {\r\n              \tDatabase.addBook(booktitleField.getText(),\r\n                  \t\t\t\tauthorField.getText(),\r\n                  \t\t\t\tgenreField.getText(),\r\n                  \t\t\t\tpubDateField.getText(),\r\n                  \t\t\t\tisbnField.getText(),\r\n                  \t\t\t\tavailableField.isSelected()\r\n                  \t\t);\r\n              \tDatabase.refreshTables(bookModel, borrowerModel, checkoutModel);\r\n                  JOptionPane.showMessageDialog(addBookButton, \"Book added successfully.\");\r\n            } catch (SQLException e1) {\r\n                e1.printStackTrace();\r\n                JOptionPane.showMessageDialog(addBookButton, \"Error adding book. Please try again.\");\r\n            }\r\n              }\r\n\r\n        \r\n          });\r\n          \r\n          JButton remBookButton = new JButton(\"Remove Book\");\r\n          remBookButton.addActionListener(new ActionListener() {\r\n          \tpublic void actionPerformed(ActionEvent e) {\r\n          \t\t\r\n          \t\ttry {\r\n            Database.delete(\"books\", deleteBookField.getText());\r\n                  JOptionPane.showMessageDialog(remBookButton, \"Book deleted successfully\");\r\n                \tDatabase.refreshTables(bookModel, borrowerModel, checkoutModel);\r\n\r\n          } catch (SQLException e1) {\r\n                  JOptionPane.showMessageDialog(remBookButton, \"Error deleting book. Please try again.\");\r\n\r\n            e1.printStackTrace();\r\n          }\r\n          \t}\r\n          });\r\n\r\n          JPanel bookPanel = new JPanel(new GridLayout(0,2));\r\n          bookPanel.setBorder(new MatteBorder(5, 5, 5, 5, (Color) new Color(0, 0, 0)));\r\n          bookPanel.add(new JLabel(\"Title:\"));\r\n          bookPanel.add(booktitleField);\r\n          bookPanel.add(new JLabel(\"Author:\"));\r\n          bookPanel.add(authorField);\r\n          bookPanel.add(new JLabel(\"Genre:\"));\r\n          bookPanel.add(genreField);\r\n          bookPanel.add(new JLabel(\"Publication Date (YYYY-MM-DD):\"));\r\n          bookPanel.add(pubDateField);\r\n          bookPanel.add(new JLabel(\"ISBN:\"));\r\n          bookPanel.add(isbnField);\r\n          bookPanel.add(new JLabel(\"Available:\"));\r\n          bookPanel.add(availableField);\r\n          bookPanel.add(new JLabel(\"\"));\r\n          bookPanel.add(addBookButton);\r\n          bookPanel.add(remBookButton);\r\n          bookPanel.add(deleteBookField);\r\n          \r\n\/\/\t        Borrower input Panel\r\n          JButton btnAddBorrower = new JButton(\"Add\");\r\n          JButton btnRemBorrower = new JButton(\"Remove\");\r\n          nameField = new JTextField();\r\n          emailField = new JTextField();\r\n          phoneField = new JTextField();\r\n          addresssField = new JTextField();\r\n          deleteBorrowerField = new JTextField();\r\n          JPanel borrowerPanel= new JPanel(new GridLayout(0,2));\r\n          borrowerPanel.setBorder(new MatteBorder(5, 5, 5, 5, (Color) new Color(0, 0, 0)));\r\n          borrowerPanel.add(new JLabel(\"Name:\"));\r\n          borrowerPanel.add(nameField);\r\n          borrowerPanel.add(new JLabel(\"Email:\"));\r\n          borrowerPanel.add(emailField);\r\n          borrowerPanel.add(new JLabel(\"Phone:\"));\r\n          borrowerPanel.add(phoneField);\r\n          borrowerPanel.add(new JLabel(\"Address:\"));\r\n          borrowerPanel.add(addresssField);\r\n          borrowerPanel.add(new JLabel(\"\"));\r\n          borrowerPanel.add(btnAddBorrower);\r\n          borrowerPanel.add(btnRemBorrower);\r\n          borrowerPanel.add(deleteBorrowerField);\r\n          btnAddBorrower.addActionListener(new ActionListener() {\r\n        \r\n        @Override\r\n        public void actionPerformed(ActionEvent e) {\r\n          try {\r\n            Database.addBorrower(nameField.getText(),\r\n                      emailField.getText(),\r\n                      phoneField.getText(),\r\n                      addresssField.getText());\r\n                    JOptionPane.showMessageDialog(btnAddBorrower, \"Borrower added successfully.\");\r\n                \tDatabase.refreshTables(bookModel, borrowerModel, checkoutModel);\r\n\r\n          } catch (SQLException e1) {\r\n                  JOptionPane.showMessageDialog(btnAddBorrower, \"Error adding borrower. Please try again.\");\r\n            e1.printStackTrace();\r\n            \r\n          }\r\n          \r\n        }\r\n      });\r\n          btnRemBorrower.addActionListener(new ActionListener() {\r\n        \r\n        @Override\r\n        public void actionPerformed(ActionEvent e) {\r\n          try {\r\n            Database.delete(\"borrowers\", deleteBorrowerField.getText());\r\n                    JOptionPane.showMessageDialog(btnRemBorrower, \"Borrower deleted successfully.\");\r\n                \tDatabase.refreshTables(bookModel, borrowerModel, checkoutModel);\r\n\r\n          } catch (SQLException e1) {\r\n                    JOptionPane.showMessageDialog(btnRemBorrower, \"Error deleting Borrower.Please try again\");\r\n            e1.printStackTrace();\r\n          }\r\n          \r\n        }\r\n      });\r\n          \r\n\/\/\t        checkout input Panel\r\n          DateFormat df = new SimpleDateFormat(\"yyyy-mm-dd\");\r\n          JButton btnAddcheckout = new JButton(\"Add\");\r\n          JButton btnRemcheckout = new JButton(\"Remove\");\r\n          bookIDField = new JTextField();\r\n          borrowerIDField = new JTextField();\r\n          checkoutDateField =new JFormattedTextField(df);\r\n          dueDateField = new JFormattedTextField(df);\r\n          returnDateField = new JFormattedTextField(df);\r\n          deletecheckoutField = new JTextField();\r\n          JPanel checkoutPanel= new JPanel(new GridLayout(0,2));\r\n          checkoutPanel.setBorder(new MatteBorder(5, 5, 5, 5, (Color) new Color(0, 0, 0)));\r\n          checkoutPanel.add(new JLabel(\"Book ID:\"));\r\n          checkoutPanel.add(bookIDField);\r\n          checkoutPanel.add(new JLabel(\"Borrower ID:\"));\r\n          checkoutPanel.add(borrowerIDField);\r\n          checkoutPanel.add(new JLabel(\"Checkout Date:\"));\r\n          checkoutPanel.add(checkoutDateField);\r\n          checkoutPanel.add(new JLabel(\"Due Date:\"));\r\n          checkoutPanel.add(dueDateField);\r\n          checkoutPanel.add(new JLabel(\"Return Date:\"));\r\n          checkoutPanel.add(returnDateField);\r\n          checkoutPanel.add(new JLabel(\"\"));\r\n          checkoutPanel.add(btnAddcheckout);\r\n          checkoutPanel.add(btnRemcheckout);\r\n          checkoutPanel.add(deletecheckoutField);\r\n          btnAddcheckout.addActionListener(new ActionListener() {\r\n        \r\n        @Override\r\n        public void actionPerformed(ActionEvent e) {\r\n          try {\r\n            Database.addCheckout(bookIDField.getText(), \r\n                      borrowerIDField.getText(),\r\n                      checkoutDateField.getText(),\r\n                      dueDateField.getText(),\r\n                      returnDateField.getText());\r\n            Database.refreshTables(bookModel, borrowerModel, checkoutModel);\r\n          } catch (SQLException e1) {\r\n                  JOptionPane.showMessageDialog(addBookButton, \"Error adding checkouts. Please try again.\");\r\n            e1.printStackTrace();\r\n          }\r\n          \r\n        }\r\n      });\r\n          btnRemcheckout.addActionListener(new ActionListener() {\r\n        \r\n        @Override\r\n        public void actionPerformed(ActionEvent e) {\r\n          try {\r\n            Database.delete(\"checkouts\", deletecheckoutField.getText());\r\n                    JOptionPane.showMessageDialog(btnRemcheckout, \"Checkout deleted successfully.\");\r\n                \tDatabase.refreshTables(bookModel, borrowerModel, checkoutModel);\r\n\r\n          } catch (SQLException e1) {\r\n                    JOptionPane.showMessageDialog(btnRemcheckout, \"Error deleting Checkout.Please try again\");\r\n            e1.printStackTrace();\r\n          }\r\n          \r\n        }\r\n      });\r\n          \r\n       \/\/ add a change listener to the tabbed pane to change the input panel accordingly\r\n          tabbedPane.addChangeListener(new ChangeListener() {\r\n              public void stateChanged(ChangeEvent e) {\r\n                  \/\/ get the index of the selected tab\r\n                  int selectedIndex = tabbedPane.getSelectedIndex();\r\n                  if(tabbedPane.getTitleAt(selectedIndex) == \"Books\") {\r\n                  \tgetContentPane().removeAll();\r\n                  \tgetContentPane().add(bookPanel, BorderLayout.NORTH);\r\n           \t        getContentPane().add(tabbedPane, BorderLayout.CENTER);\r\n           \t        \r\n                  }\r\n                  if(tabbedPane.getTitleAt(selectedIndex) == \"Borrowers\") {\r\n                  \tgetContentPane().removeAll();\r\n                  \tgetContentPane().add(borrowerPanel, BorderLayout.NORTH);\r\n           \t        getContentPane().add(tabbedPane, BorderLayout.CENTER);\r\n           \t       \r\n                  }\r\n                  if(tabbedPane.getTitleAt(selectedIndex) == \"Checkouts\") {\r\n                  \tgetContentPane().removeAll();\r\n                  \tgetContentPane().add(checkoutPanel, BorderLayout.NORTH);\r\n           \t        getContentPane().add(tabbedPane, BorderLayout.CENTER);\r\n                  }\r\n                  repaint();\r\n              }\r\n              \r\n          });\r\n          \r\n          \/\/ Add components to JFrame\r\n          getContentPane().add(bookPanel, BorderLayout.NORTH);\r\n          getContentPane().add(tabbedPane, BorderLayout.CENTER);\r\n\r\n          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r\n          setSize(800, 600);\r\n          setLocationRelativeTo(null);\r\n          setTitle(\"Library Management System by DataFlair\");\r\n          setVisible(true);\r\n      }\r\npublic static void main(String[] args) {\r\n  new LibraryManagement();\r\n}\r\n\r\n}<\/pre>\n<h3>Java Library Management System Output<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-113708 aligncenter\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/java-library-management-system-output.webp\" alt=\"java library management system output\" width=\"802\" height=\"602\" \/><\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-113709 aligncenter\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/library-management-system-output.webp\" alt=\"library management system output\" width=\"802\" height=\"602\" \/><\/h3>\n<h3>Summary<\/h3>\n<p>Throughout this project, we have learned how to create a Library Management System using Java and Swing for the UI of the application. The system includes three main tables: Books, Borrowers, and Checkouts, all of which are stored in an SQLite database.<\/p>\n<p>We have also learned how to design input panels for each of these tables, allowing us to easily add, edit, and delete entries in the database. By following this project, we now have the skills to create a fully functional Library Management System.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2624,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1lkDjOQkVIXbJ3k0vHZ3m8Xm66bpdxjXd\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601085748\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1lkDjOQkVIXbJ3k0vHZ3m8Xm66bpdxjXd\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-01 10:14:45&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-09 06:41:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-12 19:07:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-16 18:13:39&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-16 18:13:39&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project, we will learn how to create a Library Management System using Java programming language and Swing GUI library for the user interface. The system comprises three main tables: Books, Borrowers, and&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":113707,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[27426,27425,27229,22416,22417,22863,27427],"class_list":["post-113561","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java-library-management-system","tag-java-library-management-system-project","tag-java-project-for-practice","tag-java-project-ideas","tag-java-projects","tag-library-management-system","tag-library-management-system-project"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Library Management \u2013 The Backbone of Any Successful Library - DataFlair<\/title>\n<meta name=\"description\" content=\"Efficiently manage your library with our Java library management system. Streamline your operations and enhance user experience.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/java-library-management\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Library Management \u2013 The Backbone of Any Successful Library - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Efficiently manage your library with our Java library management system. Streamline your operations and enhance user experience.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/java-library-management\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-03T03:30:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T08:56:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/java-project-library-management-system.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Library Management \u2013 The Backbone of Any Successful Library - DataFlair","description":"Efficiently manage your library with our Java library management system. Streamline your operations and enhance user experience.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/java-library-management\/","og_locale":"en_US","og_type":"article","og_title":"Java Library Management \u2013 The Backbone of Any Successful Library - DataFlair","og_description":"Efficiently manage your library with our Java library management system. Streamline your operations and enhance user experience.","og_url":"https:\/\/data-flair.training\/blogs\/java-library-management\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-04-03T03:30:08+00:00","article_modified_time":"2026-06-01T08:56:51+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/java-project-library-management-system.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Java Library Management \u2013 The Backbone of Any Successful Library","datePublished":"2023-04-03T03:30:08+00:00","dateModified":"2026-06-01T08:56:51+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/"},"wordCount":890,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/java-project-library-management-system.webp","keywords":["java library management system","java library management system project","java project for practice","java project ideas","java projects","library management system","library management system project"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/java-library-management\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/","url":"https:\/\/data-flair.training\/blogs\/java-library-management\/","name":"Java Library Management \u2013 The Backbone of Any Successful Library - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/java-project-library-management-system.webp","datePublished":"2023-04-03T03:30:08+00:00","dateModified":"2026-06-01T08:56:51+00:00","description":"Efficiently manage your library with our Java library management system. Streamline your operations and enhance user experience.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/java-library-management\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/java-project-library-management-system.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/java-project-library-management-system.webp","width":1200,"height":628,"caption":"java project library management system"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/java-library-management\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Java Library Management \u2013 The Backbone of Any Successful Library"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/113561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=113561"}],"version-history":[{"count":8,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/113561\/revisions"}],"predecessor-version":[{"id":148711,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/113561\/revisions\/148711"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/113707"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=113561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=113561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=113561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}