Skip to content Skip to sidebar Skip to footer

Read Utility Txt File and Display Monthly Cost Java

AWS Global Infrastructure

Programming & Frameworks

Topics Covered

  • C Programming and Information Structures (18 Blogs)
  • Comprehensive Java Course (4 Blogs)
  • Coffee/J2EE and SOA (323 Blogs)
  • Leap Framework (8 Blogs)

Come across More

How To Create Library Management System Project in Java?

Last updated on Nov 03,2021 159.5K Views

18 / 29 Blog from Coffee Programs


In this modern era of the internet, near all of us rely on web-based applications from small to big tasks. Well, Library direction system is one of the most popular utilize-cases considered by the professionals while building applications in Java. In this article, I volition show yous how to create a library management system project in Java.

The following will exist the sequence of topics for this article:

  1. What is Coffee?
  2. What is MySQL?
  3. Library Management System Project
      • System Requirements
      • Tables Considered
      • Projection Code
      • Output

Let's get started.

What is Java?

Java is an object-oriented language similar to C++, simply with avant-garde and simplified features. Coffee is free to access  and can run  on all platforms .

The features of Coffee are as follows:

  • Simple: Java has fabricated life easier by removing all the complexities such as pointers, operator overloading as y'all come across in C++ or any other programming linguistic communication.
  • Object-oriented:E verything is considered to be an "object" which possess some country, behavior and all the operations are performed using these objects.
  • Secured:A ll the code is converted in bytecode  after compilation, which is not readable past a man . and coffee  does not utilize an explicit pointer and run the programs inside the sandbox to prevent any activities from untrusted sources. It enables to develop virus-free, tamper-complimentary systems/applications .

What is MySQL?

MySQL is an open-source relational database management system that works on many platforms. It provides multi-user access to support many storage engines and is backed by Oracle. So, y'all can buy a commercial license version from Oracle to get premium support services.

The features of MySQL are as follows:

  • Ease of Direction –The software very easily gets downloaded and besides uses an event scheduler to schedule the tasks automatically.
  • Robust Transactional Back up –Holds the Acrid (Atomicity, Consistency, Isolation, Immovability) property, and also allows distributed multi-version support.
  • Comprehensive Application Development –MySQL has plugin libraries to embed the database into any application. It also supports stored procedures, triggers, functions, views and many more for application evolution. Refer to RDS Tutorial  to empathize Amazon'due south RDBMS.

Library Management Organisation Project in Coffee

Library Management System is one of the most popular projects which is created using Java. So, in this article, I will show you how to create this project using the following system requirements.

System Requirements

To execute the below project, you will need the post-obit business requirements:

  • MySQL Community Server
  • MySQL JDBC Connector
  • Java
  • Eclipse IDE
  • rs2xml.jar

The rs2xml jar is used to display the information in a tabular array format. And then, in one case you lot create a project in Eclipse IDE, you take to import the rs2xml jar and JDBC connector JAR into the project.

To do that, correct-click on the project, choose Build Path -> Configure Build Path. In the dialog box, which opens upwards, cull Add External JARs, and add the JAR files. Once added, click on Employ and Close. Refer below.

Add External JARS- Library Management System Project in Java - EdurekaTables Considered

At present, for this detail projection, I have considered 3 tables, which are:

  • Users -> This table consists of the columns {UID, Username, Password, Admin}
  • Books-> The book's table consists of the columns {BID, Book proper noun, Cost, Genre}
  • Issue -> This table consists of the columns {IID, UID, BID, IssueDate, Menstruation, ReturnDate, Fine}

Alright, so now that the Initial ready is done, and I accept told you the schema of tables, let u.s. get started.

Library Management System Project Code

For your amend understanding, I take divided the code into the following functions and I will be explaining y'all function-wise:

  • Login
  • Connect
  • Create/ Reset
  • User Carte
  • Admin Menu

Too, to create a GUI, I will be using Swing. Swing is a library or a ready of plan components used to create graphical user interface components such every bit scroll bars, buttons, dialog boxes, etc.

Before I hash out the lawmaking of functions with you, let me prove you lot the code for the main form and the libraries to be imported:

import coffee.awt.outcome.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Locale; import java.util.concurrent.TimeUnit;  import javax.swing.*; import net.proteanit.sql.DbUtils;  public class chief { 	 	public static class ex{ 		public static int days=0; 			}  	public static void primary(Cord[] args) { 		 		login(); 		//create(); 	}                

Now in this article on Library Direction System in Java, allow us empathize the code of all the above functions.

Login

I have created this office to enable the user and the admin login. So, initially when a user logs in for the first time, that user will exist an admin by default, and the username and password will be {admin, admin}. Refer beneath.

Login - Library Management System Project in Java - Edureka

For this schema, I have considered merely one admin. So, once a user logs in as an admin, he or she will be redirected to the admin card as below. I will hash out the functions of the admin in the admin menu department.

Admin Functions - Library Management System Project in Java - Edureka

Coming dorsum to the login functions, refer to the below code:

public static void login() { 	 	JFrame f=new JFrame("Login");//creating instance of JFrame   	JLabel l1,l2;       l1=new JLabel("Username");  //Create label Username     l1.setBounds(xxx,fifteen, 100,30); //ten axis, y axis, width, summit           l2=new JLabel("Countersign");  //Create label Countersign     l2.setBounds(30,50, 100,30); 	 	 	JTextField F_user = new JTextField(); //Create text field for username 	F_user.setBounds(110, fifteen, 200, 30); 		 	JPasswordField F_pass=new JPasswordField(); //Create text field for password 	F_pass.setBounds(110, 50, 200, 30); 	   	JButton login_but=new JButton("Login");//creating instance of JButton for Login Button 	login_but.setBounds(130,90,80,25);//Dimensions for push 	login_but.addActionListener(new ActionListener() {  //Perform activity 		 		public void actionPerformed(ActionEvent eastward){   		String username = F_user.getText(); //Store username entered by the user in the variable "username" 		Cord password = F_pass.getText(); //Store password entered past the user in the variable "password" 		 		if(username.equals("")) //If username is zilch 		{             JOptionPane.showMessageDialog(null,"Please enter username"); //Display dialog box with the bulletin 		}  		else if(password.equals("")) //If password is null 		{             JOptionPane.showMessageDialog(zip,"Please enter password"); //Display dialog box with the message 		} 		else { //If both the fields are present so to login the user, check wether the user exists already 			//Arrangement.out.println("Login connect"); 			Connection connection=connect();  //Connect to the database 			try 			{ 			Statement stmt = connection.createStatement(); 		      stmt.executeUpdate("USE LIBRARY"); //Use the database with the name "Library" 		      String st = ("SELECT * FROM USERS WHERE USERNAME='"+username+"' AND PASSWORD='"+password+"'"); //Retreive username and passwords from users 		      ResultSet rs = stmt.executeQuery(st); //Execute query 		      if(rs.next()==false) { //Motility arrow beneath 		    	  System.out.impress("No user");   		          JOptionPane.showMessageDialog(cipher,"Incorrect Username/Password!"); //Display Message  		      } 		      else { 		    	  f.dispose(); 		    	rs.beforeFirst();  //Movement the pointer above 		    	while(rs.next()) 		    	{ 		    	  String admin = rs.getString("ADMIN"); //user is admin 		    	  //System.out.println(admin); 		    	  String UID = rs.getString("UID"); //Become user ID of the user 		    	  if(admin.equals("1")) { //If boolean value i 		    		  admin_menu(); //redirect to admin menu 		    	  } 		    	  else{ 		    		  user_menu(UID); //redirect to user bill of fare for that user ID 		    	  } 		      } 		      } 			} 			catch (Exception ex) { 		         ex.printStackTrace(); 		} 		} 	}				 	});  	 	f.add(F_pass); //add countersign 	f.add together(login_but);//adding button in JFrame   	f.add(F_user);	//add user     f.add(l1);  // add label1 i.due east. for username     f.add(l2); // add label2 i.e. for password      	f.setSize(400,180);//400 width and 500 height   	f.setLayout(null);//using no layout managers   	f.setVisible(true);//making the frame visible  	f.setLocationRelativeTo(zip); 	 }                

Connect

The connect office is used to connect the database to the GUI. Then, to do that, I have mentioned the beneath code:

public static Connectedness connect() { try {         Class.forName("com.mysql.cj.jdbc.Driver");         //Arrangement.out.println("Loaded commuter");         Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mysql?user=root&password=edureka");         //System.out.println("Connected to MySQL");         return con;  }   catch (Exception ex) {         ex.printStackTrace();  } return aught; }                

In the above office, we are connecting our MySQL database with the username "root" and password "edureka" to our application. Now, once the application is continued to the database, our next step is to create or reset the database. And then, next in this article on Library Management Organisation Project in Java, let us talk over the Create function..

Create

The create role is used to create the database, tables and add together data into these tables. So, to practise that, SQL statements will exist used as below.

public static void create() { 	effort { 	Connection connexion=connect(); 	ResultSet resultSet = connectedness.getMetaData().getCatalogs(); 	//iterate each catalog in the ResultSet 		while (resultSet.side by side()) { 		  // Get the database name, which is at position 1 		  String databaseName = resultSet.getString(1); 		  if(databaseName.equals("library")) { 			  //System.out.print("aye"); 			  Statement stmt = connection.createStatement(); 		      //Drib database if it pre-exists to reset the complete database 		      String sql = "Driblet DATABASE library"; 		      stmt.executeUpdate(sql); 		  } 		} 		  Statement stmt = connection.createStatement(); 	       	      String sql = "CREATE DATABASE LIBRARY"; //Create Database 	      stmt.executeUpdate(sql);  	      stmt.executeUpdate("USE LIBRARY"); //Employ Database 		  //Create Users Tabular array 	      String sql1 = "CREATE TABLE USERS(UID INT Not Nil AUTO_INCREMENT PRIMARY KEY, USERNAME VARCHAR(xxx), Countersign VARCHAR(xxx), ADMIN BOOLEAN)"; 	      stmt.executeUpdate(sql1); 		  //Insert into users tabular array 	      stmt.executeUpdate("INSERT INTO USERS(USERNAME, Countersign, ADMIN) VALUES('admin','admin',True)"); 		  //Create Books table 	      stmt.executeUpdate("CREATE TABLE BOOKS(BID INT NOT Aught AUTO_INCREMENT Principal Cardinal, BNAME VARCHAR(50), GENRE VARCHAR(20), PRICE INT)"); 		  //Create Issued Table 	      stmt.executeUpdate("CREATE Tabular array ISSUED(IID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, UID INT, BID INT, ISSUED_DATE VARCHAR(xx), RETURN_DATE VARCHAR(20), PERIOD INT, FINE INT)"); 		  //Insert into books table 	      stmt.executeUpdate("INSERT INTO BOOKS(BNAME, GENRE, Cost) VALUES ('War and Peace', 'Mystery', 200),  ('The Invitee Book', 'Fiction', 300), ('The Perfect Murder','Mystery', 150), ('Accidental Presidents', 'Biography', 250), ('The Wicked King','Fiction', 350)"); 	       	resultSet.shut(); 	} 	 take hold of (Exception ex) {          ex.printStackTrace(); } }                

Now, that we have created the database, continued with GUI and enables the login role, adjacent in this article on Library Management Organisation Project in Java, allow usa now discuss the functions of the User Menu.

User Carte du jour

The User Menu is designed to show details of all the books nowadays in the library and the books issued by the user.

public static void user_menu(String UID) { 	 	 	JFrame f=new JFrame("User Functions"); //Give dialog box name equally User functions     //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Exit user card on closing the dialog box 	JButton view_but=new JButton("View Books");//creating instance of JButton   	view_but.setBounds(20,xx,120,25);//x axis, y axis, width, height  	view_but.addActionListener(new ActionListener() {  		public void actionPerformed(ActionEvent due east){ 			 		    JFrame f = new JFrame("Books Available"); //View books stored in database 		    //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 		     		     			Connection connection = connect(); 			String sql="select * from BOOKS"; //Retreive information from database 	        endeavour { 	        	Statement stmt = connectedness.createStatement(); //connect to database 			     stmt.executeUpdate("Employ LIBRARY"); // use librabry 	            stmt=connexion.createStatement(); 	            ResultSet rs=stmt.executeQuery(sql); 	            JTable book_list= new JTable(); //evidence data in tabular array format 	            book_list.setModel(DbUtils.resultSetToTableModel(rs));  	              	            JScrollPane scrollPane = new JScrollPane(book_list); //enable scroll bar  	            f.add(scrollPane); //add scroll bar 	            f.setSize(800, 400); //set dimensions of view books frame 	            f.setVisible(true); 	        	f.setLocationRelativeTo(zip); 	        } catch (SQLException e1) { 	            // TODO Auto-generated catch block 	             JOptionPane.showMessageDialog(null, e1); 	        }   			 			 	} 	} 	); 	 	JButton my_book=new JButton("My Books");//creating instance of JButton   	my_book.setBounds(150,twenty,120,25);//x axis, y axis, width, height  	my_book.addActionListener(new ActionListener() { //Perform action 		public void actionPerformed(ActionEvent due east){ 			 			   			JFrame f = new JFrame("My Books"); //View books issued by user 		    //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 			int UID_int = Integer.parseInt(UID); //Pass user ID  		    //.iid,issued.uid,issued.bid,issued.issued_date,issued.return_date,issued, 			Connection connection = connect(); //connect to database 			//recall data 			Cord sql="select distinct issued.*,books.bname,books.genre,books.cost from issued,books " + "where ((issued.uid=" + UID_int + ") and (books.bid in (select bid from issued where issued.uid="+UID_int+"))) group past iid"; 			String sql1 = "select bid from issued where uid="+UID_int; 	        try { 	        	Statement stmt = connection.createStatement(); 				//utilize database 			     stmt.executeUpdate("USE LIBRARY"); 	            stmt=connection.createStatement(); 				//shop in array 	            ArrayList books_list = new ArrayList();   	            	             	            ResultSet rs=stmt.executeQuery(sql); 	            JTable book_list= new JTable(); //store data in table format 	            book_list.setModel(DbUtils.resultSetToTableModel(rs));  	            //enable curlicue bar 	            JScrollPane scrollPane = new JScrollPane(book_list);  	            f.add together(scrollPane); //add scroll bar 	            f.setSize(800, 400); //set dimensions of my books frame 	            f.setVisible(true); 	        	f.setLocationRelativeTo(null); 	        } catch (SQLException e1) { 	            // TODO Auto-generated grab block 	             JOptionPane.showMessageDialog(nada, e1); 	        }   			 				 	} 	} 	); 	 	 	 	f.add(my_book); //add my books 	f.add(view_but); // add view books 	f.setSize(300,100);//400 width and 500 height   	f.setLayout(zip);//using no layout managers   	f.setVisible(truthful);//making the frame visible  	f.setLocationRelativeTo(nix); 	}                

Side by side, in this article on Library Management Arrangement Projection in Java, let us discuss the lawmaking for Admin Bill of fare office.

Admin Menu

The Admin Menu is designed to testify details of users, books, issued books, add books, return books, add user, and create or reset the database.

                  public static void admin_menu() { 	 	 	JFrame f=new JFrame("Admin Functions"); //Requite dialog box name equally admin functions     //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //               JButton create_but=new JButton("Create/Reset");//creating example of JButton to create or reset database 	create_but.setBounds(450,60,120,25);//x axis, y centrality, width, meridian  	create_but.addActionListener(new ActionListener() { //Perform action 		public void actionPerformed(ActionEvent e){ 			 			create(); //Call create function 			JOptionPane.showMessageDialog(null,"Database Created/Reset!"); //Open up a dialog box and brandish the message 			 		} 	}); 	      	JButton view_but=new JButton("View Books");//creating instance of JButton to view books 	view_but.setBounds(xx,20,120,25);//x axis, y centrality, width, height  	view_but.addActionListener(new ActionListener() { 		public void actionPerformed(ActionEvent e){ 			 		    JFrame f = new JFrame("Books Available");  		    //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 		     		     			Connection connection = connect(); //connect to database 			String sql="select * from BOOKS"; //select all books  	        try { 	        	Argument stmt = connection.createStatement(); 			     stmt.executeUpdate("Utilize LIBRARY"); //use database 	            stmt=connection.createStatement(); 	            ResultSet rs=stmt.executeQuery(sql); 	            JTable book_list= new JTable(); //view information in table format 	            book_list.setModel(DbUtils.resultSetToTableModel(rs));  	            //mention scroll bar 	            JScrollPane scrollPane = new JScrollPane(book_list);   	            f.add(scrollPane); //add scrollpane 	            f.setSize(800, 400); //set size for frame 	            f.setVisible(true); 	        	f.setLocationRelativeTo(cipher); 	        } take hold of (SQLException e1) { 	            // TODO Auto-generated catch cake 	             JOptionPane.showMessageDialog(null, e1); 	        }   			 			 	} 	} 	); 	 	JButton users_but=new JButton("View Users");//creating instance of JButton to view users 	users_but.setBounds(150,20,120,25);//x axis, y centrality, width, superlative  	users_but.addActionListener(new ActionListener() { //Perform activeness on click button 		public void actionPerformed(ActionEvent e){ 				 			    JFrame f = new JFrame("Users Listing"); 			    //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 			     			     				Connection connection = connect(); 				Cord sql="select * from users"; //retrieve all users 		        try { 		        	Argument stmt = connection.createStatement(); 				     stmt.executeUpdate("USE LIBRARY"); //apply database 		            stmt=connection.createStatement(); 		            ResultSet rs=stmt.executeQuery(sql); 		            JTable book_list= new JTable(); 		            book_list.setModel(DbUtils.resultSetToTableModel(rs));  		            //mention scroll bar 		            JScrollPane scrollPane = new JScrollPane(book_list);  		            f.add together(scrollPane); //add scrollpane 		            f.setSize(800, 400); //fix size for frame 		            f.setVisible(truthful); 		        	f.setLocationRelativeTo(null); 		        } catch (SQLException e1) { 		            // TODO Machine-generated catch block 		             JOptionPane.showMessageDialog(null, e1); 		        }   	 	 			 				 	} 		} 	);	 	 	JButton issued_but=new JButton("View Issued Books");//creating case of JButton to view the issued books 	issued_but.setBounds(280,20,160,25);//x centrality, y centrality, width, height  	issued_but.addActionListener(new ActionListener() { 		public void actionPerformed(ActionEvent e){ 				 			    JFrame f = new JFrame("Users List"); 			    //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 			     			     				Connection connexion = connect(); 				String sql="select * from issued"; 		        try { 		        	Statement stmt = connection.createStatement(); 				     stmt.executeUpdate("USE LIBRARY"); 		            stmt=connection.createStatement(); 		            ResultSet rs=stmt.executeQuery(sql); 		            JTable book_list= new JTable(); 		            book_list.setModel(DbUtils.resultSetToTableModel(rs));  		             		            JScrollPane scrollPane = new JScrollPane(book_list);  		            f.add together(scrollPane); 		            f.setSize(800, 400); 		            f.setVisible(true); 		        	f.setLocationRelativeTo(null); 		        } take hold of (SQLException e1) { 		            // TODO Auto-generated grab block 		             JOptionPane.showMessageDialog(cipher, e1); 		        }   	 	 						 	} 		} 	); 	 	 	JButton add_user=new JButton("Add together User"); //creating instance of JButton to add users 	add_user.setBounds(twenty,threescore,120,25); //prepare dimensions for button 	 	add_user.addActionListener(new ActionListener() { 		public void actionPerformed(ActionEvent east){ 				 			    JFrame m = new JFrame("Enter User Details"); //Frame to enter user details 			    //g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 			    //Create label  			    JLabel l1,l2;   			    l1=new JLabel("Username");  //label 1 for username 			    l1.setBounds(thirty,fifteen, 100,30);  			     			     			    l2=new JLabel("Password");  //label 2 for password 			    l2.setBounds(30,l, 100,30);  				 				//prepare text field for username  				JTextField F_user = new JTextField(); 				F_user.setBounds(110, xv, 200, thirty); 				 				//set text field for password 				JPasswordField F_pass=new JPasswordField(); 				F_pass.setBounds(110, fifty, 200, 30); 				//prepare radio button for admin 				JRadioButton a1 = new JRadioButton("Admin"); 				a1.setBounds(55, lxxx, 200,xxx); 				//set radio button for user 				JRadioButton a2 = new JRadioButton("User"); 				a2.setBounds(130, lxxx, 200,thirty); 				//add together radio buttons 				ButtonGroup bg=new ButtonGroup();     				bg.add together(a1);bg.add(a2);   				 								 				JButton create_but=new JButton("Create");//creating example of JButton for Create  				create_but.setBounds(130,130,eighty,25);//ten axis, y centrality, width, acme  				create_but.addActionListener(new ActionListener() { 					 					public void actionPerformed(ActionEvent east){ 					 					String username = F_user.getText(); 					String password = F_pass.getText(); 					Boolean admin = faux; 					 					if(a1.isSelected()) { 						admin=true; 					} 					 					Connectedness connection = connect(); 					 					attempt { 					Statement stmt = connection.createStatement(); 				     stmt.executeUpdate("Utilise LIBRARY"); 				     stmt.executeUpdate("INSERT INTO USERS(USERNAME,Password,ADMIN) VALUES ('"+username+"','"+countersign+"',"+admin+")"); 		             JOptionPane.showMessageDialog(null,"User added!"); 		             chiliad.dispose(); 		              					} 					 					catch (SQLException e1) { 			            // TODO Car-generated catch block 			             JOptionPane.showMessageDialog(null, e1); 			        }    					 					} 					 				}); 					 				 					g.add(create_but); 					g.add(a2); 					chiliad.add together(a1); 					g.add(l1); 					g.add(l2); 					g.add(F_user); 					1000.add(F_pass); 					g.setSize(350,200);//400 width and 500 height   					k.setLayout(null);//using no layout managers   					k.setVisible(truthful);//making the frame visible  					yard.setLocationRelativeTo(zilch); 				 			     	} 	}); 		 	 	JButton add_book=new JButton("Add Book"); //creating instance of JButton for adding books 	add_book.setBounds(150,60,120,25);  	 	add_book.addActionListener(new ActionListener() { 		public void actionPerformed(ActionEvent e){ 				//set frame wot enter volume details 			    JFrame g = new JFrame("Enter Book Details"); 			    //g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 			    // set labels 			    JLabel l1,l2,l3;   			    l1=new JLabel("Volume Proper noun");  //lebel ane for book name 			    l1.setBounds(30,15, 100,30);  			     			     			    l2=new JLabel("Genre");  //label 2 for genre 			    l2.setBounds(30,53, 100,30);  			     			    l3=new JLabel("Toll");  //label 2 for price 			    l3.setBounds(30,ninety, 100,30);  				 				//set text field for book name 				JTextField F_bname = new JTextField(); 				F_bname.setBounds(110, xv, 200, xxx); 				 				//set text field for genre  				JTextField F_genre=new JTextField(); 				F_genre.setBounds(110, 53, 200, 30); 				//fix text field for price 				JTextField F_price=new JTextField(); 				F_price.setBounds(110, ninety, 200, 30); 						 				 				JButton create_but=new JButton("Submit");//creating instance of JButton to submit details   				create_but.setBounds(130,130,fourscore,25);//x axis, y axis, width, superlative  				create_but.addActionListener(new ActionListener() { 					 					public void actionPerformed(ActionEvent e){ 					// assign the book name, genre, price 					String bname = F_bname.getText(); 					String genre = F_genre.getText(); 					String price = F_price.getText(); 					//catechumen price of integer to int 					int price_int = Integer.parseInt(price); 					 					Connexion connectedness = connect(); 					 					effort { 					Statement stmt = connection.createStatement(); 				     stmt.executeUpdate("Use LIBRARY"); 				     stmt.executeUpdate("INSERT INTO BOOKS(BNAME,GENRE,Cost) VALUES ('"+bname+"','"+genre+"',"+price_int+")"); 		             JOptionPane.showMessageDialog(null,"Book added!"); 		             g.dispose(); 		              					} 					 					catch (SQLException e1) { 			            // TODO Auto-generated catch block 			             JOptionPane.showMessageDialog(null, e1); 			        }    					 					} 					 				}); 								 					one thousand.add(l3); 					g.add(create_but); 					g.add together(l1); 					g.add(l2); 					g.add(F_bname); 					one thousand.add together(F_genre); 					g.add together(F_price); 					yard.setSize(350,200);//400 width and 500 height   					g.setLayout(null);//using no layout managers   					k.setVisible(true);//making the frame visible  					g.setLocationRelativeTo(null); 						     	} 	}); 	 	 	JButton issue_book=new JButton("Issue Book"); //creating example of JButton to issue books 	issue_book.setBounds(450,20,120,25);  	 	issue_book.addActionListener(new ActionListener() { 		public void actionPerformed(ActionEvent e){ 				//enter details 			    JFrame g = new JFrame("Enter Details"); 			    //g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 			    //create labels 			    JLabel l1,l2,l3,l4;   			    l1=new JLabel("Book ID(BID)");  // Label 1 for Book ID 			    l1.setBounds(xxx,15, 100,30);  			     			     			    l2=new JLabel("User ID(UID)");  //Label 2 for user ID 			    l2.setBounds(thirty,53, 100,30);  			     			    l3=new JLabel("Period(days)");  //Label three for flow 			    l3.setBounds(30,90, 100,30);  			     			    l4=new JLabel("Issued Appointment(DD-MM-YYYY)");  //Label 4 for issue engagement 			    l4.setBounds(30,127, 150,30);  				 				JTextField F_bid = new JTextField(); 				F_bid.setBounds(110, 15, 200, 30); 				 				 				JTextField F_uid=new JTextField(); 				F_uid.setBounds(110, 53, 200, xxx); 				 				JTextField F_period=new JTextField(); 				F_period.setBounds(110, 90, 200, 30); 				 				JTextField F_issue=new JTextField(); 				F_issue.setBounds(180, 130, 130, xxx);	  				 				JButton create_but=new JButton("Submit");//creating instance of JButton   				create_but.setBounds(130,170,80,25);//ten axis, y axis, width, height  				create_but.addActionListener(new ActionListener() { 					 					public void actionPerformed(ActionEvent e){ 					 					String uid = F_uid.getText(); 					String bid = F_bid.getText(); 					String period = F_period.getText(); 					String issued_date = F_issue.getText();  					int period_int = Integer.parseInt(flow); 					 					Connection connection = connect(); 					 					try { 					Argument stmt = connexion.createStatement(); 				     stmt.executeUpdate("USE LIBRARY"); 				     stmt.executeUpdate("INSERT INTO ISSUED(UID,BID,ISSUED_DATE,Menses) VALUES ('"+uid+"','"+bid+"','"+issued_date+"',"+period_int+")"); 		             JOptionPane.showMessageDialog(null,"Book Issued!"); 		             grand.dispose(); 		              					} 					 					catch (SQLException e1) { 			            // TODO Auto-generated catch block 			             JOptionPane.showMessageDialog(zero, e1); 			        }    					 					} 					 				}); 					 				 					chiliad.add(l3); 					g.add together(l4); 					one thousand.add together(create_but); 					grand.add(l1); 					g.add(l2); 					g.add(F_uid); 					one thousand.add(F_bid); 					yard.add(F_period); 					m.add together(F_issue); 					g.setSize(350,250);//400 width and 500 height   					g.setLayout(nada);//using no layout managers   					g.setVisible(true);//making the frame visible  					thousand.setLocationRelativeTo(cypher); 				 			     	} 	}); 	 	 	JButton return_book=new JButton("Return Book"); //creating example of JButton to return books 	return_book.setBounds(280,60,160,25);  	 	return_book.addActionListener(new ActionListener() { 		public void actionPerformed(ActionEvent e){ 				 			    JFrame 1000 = new JFrame("Enter Details"); 			    //g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 			    //set labels  			    JLabel l1,l2,l3,l4;   			    l1=new JLabel("Issue ID(IID)");  //Label 1 for Issue ID 			    l1.setBounds(thirty,15, 100,30);  			    			     			    l4=new JLabel("Return Date(DD-MM-YYYY)");   			    l4.setBounds(30,fifty, 150,30);  				 				JTextField F_iid = new JTextField(); 				F_iid.setBounds(110, 15, 200, thirty); 				 				 				JTextField F_return=new JTextField(); 				F_return.setBounds(180, l, 130, 30); 			  				JButton create_but=new JButton("Render");//creating instance of JButton to mention return appointment and calculcate fine 				create_but.setBounds(130,170,80,25);//x axis, y axis, width, height  				create_but.addActionListener(new ActionListener() { 					 					public void actionPerformed(ActionEvent e){					 					 					String iid = F_iid.getText(); 					String return_date = F_return.getText(); 					 					Connection connection = connect(); 					 					try { 					Statement stmt = connectedness.createStatement(); 				     stmt.executeUpdate("Use LIBRARY"); 				     //Intialize date1 with Nix value 				     String date1=cipher; 				     String date2=return_date; //Intialize date2 with return date 				     				     //select effect date 				     ResultSet rs = stmt.executeQuery("SELECT ISSUED_DATE FROM ISSUED WHERE IID="+iid); 				     while (rs.side by side()) { 				         date1 = rs.getString(ane); 				          				       } 				      				     try { 				    	 	Date date_1=new SimpleDateFormat("dd-MM-yyyy").parse(date1); 							Engagement date_2=new SimpleDateFormat("dd-MM-yyyy").parse(date2); 							//subtract the dates and store in diff 						    long unequal = date_2.getTime() - date_1.getTime(); 							//Convert diff from milliseconds to days 						    ex.days=(int)(TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS)); 						     						     						} take hold of (ParseException e1) { 							// TODO Auto-generated catch cake 							e1.printStackTrace(); 						} 				      				     				     //update return date 				     stmt.executeUpdate("UPDATE ISSUED SET RETURN_DATE='"+return_date+"' WHERE IID="+iid); 		             g.dispose(); 		               		             Connection connection1 = connect(); 		             Argument stmt1 = connection1.createStatement(); 				     stmt1.executeUpdate("Utilise LIBRARY");				 					ResultSet rs1 = stmt1.executeQuery("SELECT Catamenia FROM ISSUED WHERE IID="+iid); //prepare period 				    String diff=cypher;  					while (rs1.side by side()) { 				         diff = rs1.getString(1); 				          				       } 					int diff_int = Integer.parseInt(diff); 					if(ex.days>diff_int) { //If number of days are more the period and then calculcate fine 						 						//System.out.println(ex.days); 						int fine = (ex.days-diff_int)*10; //fine for every twenty-four hour period after the period is Rs 10. 						//update fine in the system 						stmt1.executeUpdate("UPDATE ISSUED SET FINE="+fine+" WHERE IID="+iid);	 						String fine_str = ("Fine: Rs. "+fine); 						JOptionPane.showMessageDialog(null,fine_str); 						 					}  		             JOptionPane.showMessageDialog(null,"Book Returned!"); 				      					} 							 					 					catch (SQLException e1) { 			            // TODO Automobile-generated catch block 			             JOptionPane.showMessageDialog(nothing, e1); 			        }    					 					} 					 				});	 					g.add(l4); 					g.add(create_but); 					g.add(l1); 					g.add(F_iid); 					g.add(F_return); 					m.setSize(350,250);//400 width and 500 superlative   					g.setLayout(nada);//using no layout managers   					g.setVisible(truthful);//making the frame visible  					yard.setLocationRelativeTo(nada);			     	} 	}); 	 	f.add(create_but); 	f.add(return_book); 	f.add(issue_book); 	f.add(add_book); 	f.add(issued_but); 	f.add together(users_but); 	f.add(view_but); 	f.add(add_user); 	f.setSize(600,200);//400 width and 500 height   	f.setLayout(cipher);//using no layout managers   	f.setVisible(truthful);//making the frame visible  	f.setLocationRelativeTo(nada); 	 	} }              

Now that you have understood all the functions, let us execute our library management organisation project in Java and run into the outputs.

Output:

Execute the application past clicking on the run button. Once, you execute y'all volition encounter the below dialog box. In the below dialog box, mention username and password equally {admin, admin}. Then click on the Login button.

Login Admin - Library Management System Project in Java - Edureka

Once yous click on the Login button, yous volition see the below dialog box opening upwards.

Admin Functions - Library Management System Project in Java - Edureka

Hither y'all have various options which you lot can explore. And then, permit the states get-go with the first one:

View Books

Once, you lot click on View Books button, you lot volition see the beneath frame displaying all the books present in the database, with their details.

Books Available - Library Management System Project in Java - Edureka

View Users

The View Users button is used to view the current users on the system. Since nosotros just have only one user present i.eastward the admin, it will show you output as beneath:

Users List - Library Management System Project in Java - Edureka

Create/Reset

This functionality is used to create or reset a database. So, one time you click on the button Create/Rest, you lot will see the below output:

Database Created - Library Management System Project in Java - Edureka

Add together User

To add a user, click on the selection "Add User" and mention details such as username, password and choose the radio push button user or admin. Past default, it will be the user. Then, click on Create.

Login User - Library Management System Project in Java - Edureka

In one case the user is created, you will see an output as below:

User Added - Library Management System Project in Java - Edureka

Now, once again if you click on View Users button, you will meet the below output:

User List - Library Management System Project in Java - Edureka

Alright, then now that nosotros take added a user. Let us say, that detail user wants to event books. To do that, the user has to choose the option of Event Volume.

Issue Book

Suppose, if you are the user, once you click on the Issue Book button, you lot take to mention the Book ID, User ID, Catamenia(Number of days for issuing the book), and the Issue Engagement as follows:

Issue Books - Library Management System Project in Java - Edureka

Then click on Submit. In one case, you click on Submit, you will see the beneath dialog box:

Books Issued - Library Management System Project in Java - Edureka

Now, if you want to see the issued books details, you can use the View Issued Books functionality.

View Issued Books

Once yous click on this push button, you lot will see the following output:

User Details - Library Management System Project in Java - Edureka

Alright, so, at present if the user logs in to the system, using the login role, every bit below:

User - Library Management System Project in Java - EdurekaSo the user will see the below User Carte.

User Functions - Library Management System Project in Java - Edureka

Here, the user tin view all the books in the database past using the View Books selection and the books issued by the user in the My Books department every bit below:

Books - Library Management System Project in Java - Edureka

Now, if you wish to render the book, then you have to cull the option of Render Book.

Return Volume

Once, you click on the Return Book, mention the Upshot ID and the return engagement every bit below. And then click on Return.

Return Books - Library Management System Project in Java - EdurekaAnd then, yous see a message box displaying the fine.

Calculate Fine - Library Management System Project in Java - Edureka

After that, yous once more come across a dialog box, showing the message "Book Returned". Refer below.

Book Returned - Library Management System Project in Java - Edureka

Now, if yous click on the View Issued Books, you lot will see the below output:

Show User Details - Library Management System Project in Java - Edureka

Lastly, if you lot wish to add together a book, you tin can utilise the option of Add Book.

Add Book

Click on the Add Volume push button, and mention the volume name, genre and cost. And so, click on the Submit button. Refer below.

Add Books - Library Management System Project in Java - Edureka

You will meet a dialog box displaying the below message:

Books Added - Library Management System Project in Java - Edureka

Autonomously from this, y'all can also, meet the added books in the View Books section as below:

Books Available In Database - Library Management System Project in Java - Edureka

This brings us to the terminate of our article on Library Management Organization Projection in Coffee. I hope you found this article informative and added value to your cognition.

Check out theJava Certification Training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread beyond the globe. Edureka's Java J2EE and SOA training and certification form is designed for students and professionals who desire to be a Java Developer. The course is designed to give y'all a caput starting time into Coffee programming and railroad train you for both cadre and advanced Coffee concepts along with various Coffee frameworks like Hibernate & Spring.

Got a question for us? Please mention it in the comments section of this "Library Management System Project in Java" article and we will get dorsum to you every bit before long equally possible or you tin join Java Training in UAE.

Browse Categories

webinar Annals FOR FREE WEBINAR

webinar_success Thank y'all for registering Join Edureka Meetup customs for 100+ Costless Webinars each month JOIN MEETUP Group

nolencassenthe58.blogspot.com

Source: https://www.edureka.co/blog/library-management-system-project-in-java

Enviar um comentário for "Read Utility Txt File and Display Monthly Cost Java"