0% found this document useful (0 votes)
72 views

Library Management System

This document describes the database structure and source code for forms in a library management system. The database contains tables for login, publishers, members, libraries, book issues, and book returns. The source code shows how to create login and reset password forms, add and edit publishers, and navigate between main, publisher, and member forms using menu options. Functions are included for connecting to the database, querying and updating records, and validating/resetting form fields.

Uploaded by

Naitik sethia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Library Management System

This document describes the database structure and source code for forms in a library management system. The database contains tables for login, publishers, members, libraries, book issues, and book returns. The source code shows how to create login and reset password forms, add and edit publishers, and navigate between main, publisher, and member forms using menu options. Functions are included for connecting to the database, querying and updating records, and validating/resetting form fields.

Uploaded by

Naitik sethia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 74

Library Management System

Database Structure
Tables in Database:-

Login Table:-

Publisher Table :-

1|Page
Library Management System

Member Table:-

Lib Table:-

Missue Table:-

2|Page
Library Management System

Tissue Table :-

3|Page
Library Management System

Login Form

Source Code:-
Login Button:-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String usg=txtid.getText(),us = null;

String pass=txtpa.getText(),ps = null;

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");


4|Page
Library Management System
Statement stmt=(Statement) con.createStatement();

String sql="Select * from login";

ResultSet rs=stmt.executeQuery(sql);

if(rs.next()){

us=rs.getString("login");

ps=rs.getString("Password"); }

rs.close();

con.close();

stmt.close();

catch(Exception e){

if(us.equals(usg)&& pass.equals(ps)){

Main main= new Main();

main.setVisible(true);

this.setVisible(false);}

else {

JOptionPane.showMessageDialog(this,"Login Failed"); }

Reset Password Label:-


private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {

resetpass rp=new resetpass();

5|Page
Library Management System
rp.setVisible(true);

this.setVisible(false);

Reset Form

Source Code:-
Change Button:-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String old=txtpa.getText();

String newp=txtpa1.getText();

String newp1=txtpa2.getText();

if(newp.equals(newp1)){

6|Page
Library Management System
String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

int opt = JOptionPane.showConfirmDialog(null, "Are you sure to update this record ?");

if (opt == JOptionPane.YES_OPTION){

String sql="Update login set password='"+newp+"' where password='"+old+"'";

stmt.executeUpdate(sql);

JOptionPane.showMessageDialog(this,"Password Sucessfully changed");

Login lo=new Login();

lo.setVisible(false);

this.setVisible(false);

con.close();

stmt.close();

catch(Exception e){

else{

JOptionPane.showMessageDialog(this,"new & retyped password aren't same");

}}

7|Page
Library Management System

Main Form

Source Code:-
Menu Bar:-
private void mnuPubActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Publisher pub=new Publisher();

pub.setVisible(true); }

8|Page
Library Management System
private void mnuPModActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Publisher_edit pube=new Publisher_edit();

pube.setVisible(true); }

private void mnuLibActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Book bk=new Book();

bk.setVisible(true); }

private void mnuLibEditActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Book_edit bke=new Book_edit();

bke.setVisible(true); }

private void mnuIssueActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Issue_Book bki=new Issue_Book();

bki.setVisible(true);}

private void mnuReturnActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Return_Book bke=new Return_Book();

9|Page
Library Management System
bke.setVisible(true); }

private void mnuMembActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Member bke=new Member();

bke.setVisible(true); }

private void mnuMModActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Member_edit bktdye=new Member_edit();

bktdye.setVisible(true); }

private void mnuABListActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Books_avialble bke=new Books_avialble();

bke.setVisible(true); }

private void mnuIBListActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

Issued_bookslist bke=new Issued_bookslist();

bke.setVisible(true); }

private void mnuMListActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);
10 | P a g e
Library Management System
Member_list bke=new Member_list();

bke.setVisible(true); }

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0);}

Publisher Form

Source Code:-
Window Gained Focus :-
11 | P a g e
Library Management System
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

cmdSave.setEnabled(false);

New Button:-
private void cmdNewActionPerformed(java.awt.event.ActionEvent evt) {

cmdSave.setEnabled(true);

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

String SQL = "SELECT * FROM publisher";

stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(SQL);

int PID=0;

while (rs.next()) {

PID = rs.getInt("pub_id");

PID++;

txtPno.setText(Integer.toString(PID));

txtPName.setFocusable(true);

con.close();
12 | P a g e
Library Management System
rs.close();

stmt.close();

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

}}

Save Button:-
private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

String SQL = "SELECT * FROM publisher";

stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(SQL);

int Pno = Integer.parseInt(txtPno.getText());

String PName = txtPName.getText();

String PAdd = txtPAdd.getText();

String Pph1 = txtPh1.getText();

String Pph2 = txtPh2.getText();

13 | P a g e
Library Management System
int code = JOptionPane.showConfirmDialog(this, "Are you sure to add?",
"Confirmation Dialog Box", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE);

if (code == JOptionPane.YES_OPTION) {

String strSQL = "INSERT INTO Publisher(pub_id, pub_name, pub_address,


pub_phone1, pub_phone) VALUES ("+(Pno)+", '"+(PName)+"', '"+(PAdd)+"', '"+(Pph1)+"', '"+
(Pph2)+"')";

int rowsEffected = stmt.executeUpdate(strSQL);

JOptionPane.showMessageDialog(this, "Record added successfully into


Publisher table");

txtPno.setText("");

txtPName.setText("");

txtPAdd.setText("");

txtPh1.setText("");

txtPh2.setText("");

cmdSave.setEnabled(false);

con.close();

stmt.close();

rs.close();

cmdSave.setEnabled(false);

} catch (Exception e) {
14 | P a g e
Library Management System
JOptionPane.showMessageDialog(this, e.getMessage());

Clear Button:-
private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {

txtPno.setText("");

txtPName.setText("");

txtPAdd.setText("");

txtPh1.setText("");

txtPh2.setText("");

cmdSave.setEnabled(false);

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);

Publisher Edit Form


15 | P a g e
Library Management System

Source Code:-
Window’s Gained Focus Event:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

txtPno.setEditable(false);

DefaultListModel dModel = (DefaultListModel) jList1.getModel();

dModel.clear();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)


16 | P a g e
Library Management System
DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = null;

ResultSet rs = null;

String SQL = "SELECT * FROM Publisher";

stmt = (Statement) con.createStatement();

rs = stmt.executeQuery(SQL);

while (rs.next()) {

String Pno = rs.getString("pub_id");

String PName = rs.getString("pub_name");

dModel.addElement(Pno + "- " + PName);

jList1.setModel(dModel);

con.close();

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

}}

Mouse Clicked:-
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

String MPub = (String) jList1.getSelectedValue();

String PubN =MPub.trim().substring(0,1);

String query = "SELECT * FROM Publisher WHERE pub_Id = " + PubN + ";";

try {

17 | P a g e
Library Management System
Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(query);

if (rs.next()) {

String PubName = rs.getString("pub_name");

String PubAdd = rs.getString("pub_address");

String PubPh1 = rs.getString("pub_phone1");

String PubPh2 = rs.getString("pub_phone");

txtPno.setText(PubN);

txtPName.setText(PubName);

txtPAdd.setText(PubAdd);

txtPh1.setText(PubPh1);

txtPh2.setText(PubPh2);

txtPno.setEditable(false);

con.close();

stmt.close();

rs.close();

} else {

JOptionPane.showMessageDialog(null, "Record does not found in Publisher


table"); }

} catch (Exception e) {

18 | P a g e
Library Management System
JOptionPane.showMessageDialog(this, e.getMessage());

}}

Update Button:-
private void cmdUpdateActionPerformed(java.awt.event.ActionEvent evt) {

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

stmt = (Statement) con.createStatement();

int pno = Integer.parseInt(txtPno.getText().trim());

String PubName = txtPName.getText();

String PubAdd = txtPAdd.getText();

String PubPh1 = txtPh1.getText();

String PubPh2 = txtPh2.getText();

String strSQL = "Update publisher set pub_name ='"+(PubName)+"',pub_address


= '"+(PubAdd)+"', pub_phone1 = '"+(PubPh1)+"', pub_phone = '"+(PubPh2)+"' where pub_id =
" + (pno);

stmt.executeUpdate(strSQL);

19 | P a g e
Library Management System
JOptionPane.showMessageDialog(this,"Record modified");

con.close();

stmt.close();

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Delete Button:-
private void cmdDeleteActionPerformed(java.awt.event.ActionEvent evt) {

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

stmt = (Statement) con.createStatement();

int pno = Integer.parseInt(txtPno.getText().trim());

int opt = JOptionPane.showConfirmDialog(null, "Are you sure to delete this


record ?");

if (opt == JOptionPane.YES_OPTION)

try {

String strSQL = "Delete from publisher where pub_id="+pno;


20 | P a g e
Library Management System
stmt.executeUpdate(strSQL);

JOptionPane.showMessageDialog(this,"Record Deleted");

txtPno.setText("");

txtPName.setText("");

txtPAdd.setText("");

txtPh1.setText("");

txtPh2.setText("");

txtPno.setEditable(true);

} catch (Exception e) {

JOptionPane.showMessageDialog(null, "Unable to delete");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);

21 | P a g e
Library Management System

Book Form

Source Code:-
Window’s Gained Focus Event:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

cmdSave.setEnabled(false);

22 | P a g e
Library Management System
String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement s=(Statement) con.createStatement();

String sql="Select curdate() as D";

ResultSet r=s.executeQuery(sql);

if(r.next()){

txtPDate.setText(""+r.getString("D"));

r.close();

con.close();

s.close();

catch(Exception e){

New Button:-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

cmdSave.setEnabled(true);

DefaultComboBoxModel cModel = (DefaultComboBoxModel) cbox1.getModel();


23 | P a g e
Library Management System
String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

String SQL = "SELECT * FROM lib";

stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(SQL);

int ACNO = 0;

while (rs.next()) {

ACNO = rs.getInt("acc_no");

ACNO++;

txtAcno.setText(Integer.toString(ACNO));

Statement stmt1 = (Statement) con.createStatement();

ResultSet rs1 = stmt1.executeQuery("SELECT * FROM publisher");

while (rs1.next()) {

String pubno = rs1.getString("pub_id");

String pubName = rs1.getString("pub_name");

cModel.addElement(pubno + "- " + pubName);

24 | P a g e
Library Management System
con.close();

rs.close();

stmt.close();

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

Save Button:-
private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {

DefaultComboBoxModel cModel = (DefaultComboBoxModel) cbox1.getModel();

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

int Acno = Integer.parseInt(txtAcno.getText().trim());

String bTitle = txtBTitle.getText();

String Auth1 = txtAuth1.getText();

String Auth2 = txtAuth2.getText();

String pName = (String) cbox1.getSelectedItem();

String PubNo = String.valueOf(pName.substring(0, 3).trim());

25 | P a g e
Library Management System
int pno = Integer.parseInt(PubNo);

char status='Y';

float Price = Float.parseFloat(txtPrice.getText());

int pages = Integer.parseInt(txtPages.getText());

int edition = Integer.parseInt(txtEdition.getText());

String Pdate = txtPDate.getText();

int code = JOptionPane.showConfirmDialog(this, "Are you sure to add?",


"Confirmation Dialog Box", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE);

if (code == JOptionPane.YES_OPTION) {

String strSQL = "INSERT INTO Lib(acc_no, btitle, author1, author2, pub_id, price,
pdate, pages, edition,status) VALUES ("

+(Acno)+", '"+(bTitle)+"', '"+(Auth1)+"', '"+(Auth2)+"', "+(pno)+", "+(Price)+",


'"+(Pdate)+"', "+(pages)+", "

+(edition)+",'"+(status)+"')";

stmt.executeUpdate(strSQL);

JOptionPane.showMessageDialog(this, "Record added successfully into Lib


table");

txtAcno.setText("");

txtBTitle.setText("");

txtAuth1.setText("");

txtAuth2.setText("");

cModel.removeAllElements();

txtPrice.setText("");

26 | P a g e
Library Management System
txtPages.setText("");

txtEdition.setText("");

cmdSave.setEnabled(false);

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}}

Clear Button:-
DefaultComboBoxModel cModel = (DefaultComboBoxModel) cbox1.getModel();

txtAcno.setText("");

txtBTitle.setText("");

txtAuth1.setText("");

txtAuth2.setText("");

cModel.removeAllElements();

txtPrice.setText("");

txtPages.setText("");

txtEdition.setText("");

Exit Button:-
this.setVisible(false);

new Main().setVisible(true);

27 | P a g e
Library Management System

Book Edit Form

28 | P a g e
Library Management System

Source Code:-
Window’s Gained Focus:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

DefaultListModel dModel = (DefaultListModel) jList1.getModel();

dModel.clear();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)


29 | P a g e
Library Management System

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM Lib");

while (rs.next()) {

String Ano = rs.getString("acc_no");

String BTitle = rs.getString("btitle");

dModel.addElement(Ano + "- " + BTitle);

jList1.setModel(dModel);

DefaultComboBoxModel cModel = (DefaultComboBoxModel)


jComboBox1.getModel();

cModel.removeAllElements();

Statement stmt1 = (Statement) con.createStatement();

ResultSet rs1 = stmt1.executeQuery("SELECT * FROM publisher");

while (rs1.next()) {

String pubno = rs1.getString("pub_id");

String pubName = rs1.getString("pub_name");

cModel.addElement(pubno + "- " + pubName);

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

30 | P a g e
Library Management System
}

Update Button:-
try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

int Acno = Integer.parseInt(txtAcno.getText().trim());

String bTitle = txtBTitle.getText();

String Auth1 = txtAuth1.getText();

String Auth2 = txtAuth2.getText();

String pName = (String) jComboBox1.getSelectedItem();

String NPubNo = String.valueOf(pName.substring(0, 3).trim());

int Npno = Integer.parseInt(NPubNo);

float Price = Float.parseFloat(txtPrice.getText());

int pages = Integer.parseInt(txtPages.getText());

int edition = Integer.parseInt(txtEdition.getText());

String Pdate = txtPDate.getText();


31 | P a g e
Library Management System
String strSQL = "Update Lib set btitle ='"+(bTitle)+"', author1 = '"+(Auth1)+"',
author2 = '"+(Auth2)+"', pub_id = "+(Npno)+", price = "+(Price)+", pdate = '"+(Pdate)+"', pages
= "+(pages)+ ", edition = "+(edition)+" where acc_no = " + (Acno);

stmt.executeUpdate(strSQL);

JOptionPane.showMessageDialog(this,"Record modified");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Mouse Clicked:-
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

String MBook = (String) jList1.getSelectedValue();

String Acno =MBook.trim().substring(0, 1);

String query = "SELECT * FROM Lib WHERE acc_no = " + Acno + ";";

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(query);

if (rs.next()) {

String bTitle = rs.getString("btitle");

String Auth1 = rs.getString("author1");

String Auth2 = rs.getString("author2");


32 | P a g e
Library Management System
String PID = rs.getString("pub_id");

String Price = rs.getString("price");

String PDate = rs.getString("pdate");

String pages = rs.getString("pages");

String edition = rs.getString("edition");

Connection conn = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement st = (Statement) con.createStatement();

String sql="Select * from publisher where pub_id ="+PID;

ResultSet rss=st.executeQuery(sql);

String publisher="";

if(rss.next()){

publisher=rss.getString("pub_name");

cModel.setSelectedItem(PID + "- " + publisher);

txtAcno.setText(Acno);

txtBTitle.setText(bTitle);

txtAuth1.setText(Auth1);

txtAuth2.setText(Auth2);

txtPID.setText(PID);

33 | P a g e
Library Management System
txtPrice.setText(Price);

txtPDate.setText(PDate);

txtPages.setText(pages);

txtEdition.setText(edition);

con.close();

stmt.close();

rs.close();

} else {

JOptionPane.showMessageDialog(null, "Record does not found in Student


table");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Delete Button:-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

34 | P a g e
Library Management System
int pno = Integer.parseInt(txtAcno.getText().trim());

int opt = JOptionPane.showConfirmDialog(null, "Are you sure to delete this


record ?");

if (opt == JOptionPane.YES_OPTION)

try {

String strSQL = "Delete from lib where Acc_no="+pno;

stmt.executeUpdate(strSQL);

JOptionPane.showMessageDialog(this,"Record Deleted");

txtBTitle.setText("");

txtAuth1.setText("");

txtAuth2.setText("");

txtEdition.setText("");

txtPDate.setText("");

txtPID.setText("");

txtPages.setText("");

txtPrice.setText("");

DefaultComboBoxModel cModel = (DefaultComboBoxModel)


jComboBox1.getModel();

cModel.removeAllElements();

txtAcno.setText("");

jList1.removeAll();
35 | P a g e
Library Management System
} catch (Exception e) {

JOptionPane.showMessageDialog(null, "Unable to delete");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);}

Book Issue Form

36 | P a g e
Library Management System

Source Code:-
Statement stmt = null;

ResultSet rs = null;

char st1 = 'N';

char ms = 'Y';

String SQL = "SELECT * FROM Member WHERE mem_issue = '" + st1+"'";

37 | P a g e
Library Management System
Statement stmt1 = null;

ResultSet rs1 = null;

char st = 'Y'; // Lib table

String SQL1 = "SELECT * FROM Lib WHERE status = '" + st + "';";

Statement stmt2 = null;

ResultSet rs2 = null;

String SQL2 = "SELECT * FROM Missue";

Statement stmt3 = null;

ResultSet rs3 = null;

String SQL3 = "SELECT * FROM Tissue";

Window’s Gained Focus:-


private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement s=(Statement) con.createStatement();

String sql="Select curdate() as D";

ResultSet r=s.executeQuery(sql);

if(r.next()){

txtIDate.setText(""+r.getString("D"));

}
38 | P a g e
Library Management System
r.close();

con.close();

s.close();

catch(Exception e){

} txtMNo.setEnabled(false);

txtMName.setEnabled(false);

txtMDate.setEnabled(false);

txtMStatus.setEnabled(false);

txtAcno.setEnabled(false);

txtBTitle.setEnabled(false);

txtAuth1.setEnabled(false);

txtPID.setEnabled(false);

txtStatus.setEnabled(false);

DefaultListModel dModel = (DefaultListModel) jList1.getModel();

dModel.clear();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

stmt = (Statement) con.createStatement();


39 | P a g e
Library Management System
rs = stmt.executeQuery(SQL);

while (rs.next()) {

String Mno = rs.getString("memb_no");

String MName = rs.getString("memb_name");

dModel.addElement(Mno + "- " + MName);

jList1.setModel(dModel);

DefaultListModel cModel = (DefaultListModel) jList2.getModel();

cModel.clear();

stmt1 = (Statement) con.createStatement();

rs1 = stmt1.executeQuery(SQL1);

while (rs1.next()) {

String Ano = rs1.getString("acc_no");

String BTitle = rs1.getString("btitle");

cModel.addElement(Ano + "- " + BTitle);

jList2.setModel(cModel);

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();
40 | P a g e
Library Management System
}

Mouse Clicked(list 1):-


private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

String MembNo = (String) jList1.getSelectedValue();

String Mno =MembNo.trim().substring(0, 3);

String query = "SELECT * FROM Member WHERE memb_no = " + (Mno) + ";";

try {

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

stmt = (Statement) con.createStatement();

rs = stmt.executeQuery(query);

if (rs.next()) {

String MName = rs.getString("memb_name");

String MDate = rs.getString("mdate");

String MStatus = rs.getString("mem_issue");

txtMNo.setText(Mno);

txtMName.setText(MName);

txtMDate.setText(MDate);

txtMStatus.setText(MStatus);

} else {
41 | P a g e
Library Management System
JOptionPane.showMessageDialog(null, "Record does not found in Member
table");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Mouse Clicked(list 2):-


private void jList2MouseClicked(java.awt.event.MouseEvent evt) {

String MBook = (String) jList2.getSelectedValue();

String Acno =MBook.trim().substring(0, 3);

String query = "SELECT * FROM Lib WHERE acc_no = " + Acno + ";";

try {

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

stmt1 = (Statement) con.createStatement();

rs1 = stmt1.executeQuery(query);

if (rs1.next()) {

String bTitle = rs1.getString("btitle");

String Auth1 = rs1.getString("author1");

42 | P a g e
Library Management System
String PID = rs1.getString("pub_id");

String PStatus = rs1.getString("status");

txtAcno.setText(Acno);

txtBTitle.setText(bTitle);

txtAuth1.setText(Auth1);

txtPID.setText(PID);

txtStatus.setText(PStatus);

} else {

JOptionPane.showMessageDialog(null, "Record does not found in Libdent


table");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Issue Button:-
private void cmdIssueActionPerformed(java.awt.event.ActionEvent evt) {

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

43 | P a g e
Library Management System
stmt2 = (Statement) con.createStatement();

rs2 = stmt.executeQuery(SQL);

stmt3 = (Statement) con.createStatement();

rs3 = stmt.executeQuery(SQL);

int Acno = Integer.parseInt(txtAcno.getText().trim());

int Mno = Integer.parseInt(txtMNo.getText().trim());

String idt = txtIDate.getText();

String rdt = idt;

int code = JOptionPane.showConfirmDialog(this, "Are you sure to add?",


"Confirmation Dialog Box", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE);

if (code == JOptionPane.YES_OPTION) {

String strSQL = "INSERT INTO Missue(acc_no, memb_no, idate, rdate)


VALUES ("+(Acno)+", "+(Mno)+", '"+(idt)+"', '"+(rdt)+"')";

String strSQL1 = "INSERT INTO Tissue(acc_no, memb_no, idate, rdate) VALUES


("+(Acno)+", "+(Mno)+", '"+(idt)+"', '"+(rdt)+"')";

stmt2.executeUpdate(strSQL);

stmt3.executeUpdate(strSQL1);

char sta = 'N'

String strSQLa = "Update Lib set status ='"+(sta)+"' where acc_no = " + (Acno);

stmt1.executeUpdate(strSQLa);

char stb = 'Y';

44 | P a g e
Library Management System
String strSQLb = "Update Member set mem_issue ='"+(stb)+"' where memb_no
= " + (Mno);

stmt.executeUpdate(strSQLb);

JOptionPane.showMessageDialog(this, "Book issued sucessfully");

txtAcno.setText("");

txtBTitle.setText("");

txtAuth1.setText("");

txtPID.setText("");

txtStatus.setText("");

txtMNo.setText("");

txtMName.setText("");

txtMDate.setText("");

txtMStatus.setText("");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);
45 | P a g e
Library Management System
}

46 | P a g e
Library Management System

Book ReturnForm

Source Code:-
Statement stmt = null;

ResultSet rs = null;

char st1 = 'Y';


47 | P a g e
Library Management System
String SQL = "SELECT * FROM Member WHERE mem_issue = '" + st1 + "';";

Statement stmt1 = null;

ResultSet rs1 = null;

char st = 'Y';

String SQL1 = "SELECT * FROM Lib WHERE status = '" + st + "';";

Statement stmt2 = null;

ResultSet rs2 = null;

String SQL2 = "SELECT * FROM Missue";

Statement stmt3 = null;

ResultSet rs3 = null;

String SQL3 = "SELECT * FROM Tissue";

Statement stmt4 = null;

ResultSet rs4 = null;

Window’s Gained Focus:-


private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement s=(Statement) con.createStatement();

48 | P a g e
Library Management System
String sql="Select curdate() as D";

ResultSet r=s.executeQuery(sql);

if(r.next()){

txtDate.setText(""+r.getString("D"));

r.close();

con.close();

s.close();

catch(Exception e){

txtMNo.setEditable(false);

txtMName.setEditable(false);

txtMDate.setEditable(false);

txtMStatus.setEditable(false);

txtAcno.setEditable(false);

txtBTitle.setEditable(false);

txtAuth.setEditable(false);

DefaultListModel dModel = (DefaultListModel) jList1.getModel();

49 | P a g e
Library Management System
dModel.clear();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

stmt = (Statement) con.createStatement();

rs = stmt.executeQuery(SQL);

while (rs.next()) {

String Mno = rs.getString("memb_no");

String MName = rs.getString("memb_name");

dModel.addElement(Mno + "- " + MName);

jList1.setModel(dModel);

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

}}

Return Button:-
private void cmdReturnActionPerformed(java.awt.event.ActionEvent evt) {

try {

Class.forName("com.mysql.jdbc.Driver");
50 | P a g e
Library Management System
Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

int Mno = 0, Acno = 0;

Mno = Integer.parseInt(txtMNo.getText().trim());

Acno = Integer.parseInt(txtAcno.getText().trim());

int opt = JOptionPane.showConfirmDialog(null, "Are you sure to return this


book ?");

if (opt == JOptionPane.YES_OPTION)

String query="Select datediff(curdate(),Idate) as date from tissue where


Acc_no="+Acno+" and Memb_no="+Mno;

String strSQLr = "Delete from Tissue where memb_no = " + (Mno);

stmt3.executeUpdate(strSQLr);

char sta = 'Y';

String strSQLa = "Update Lib set status ='"+(sta)+"' where acc_no = " + (Acno);

stmt1.executeUpdate(strSQLa);

char stb = 'N';

String strSQLb = "Update Member set mem_issue ='"+(stb)+"' where memb_no


= " + (Mno);

stmt.executeUpdate(strSQLb);

JOptionPane.showMessageDialog(this, "Thanks for returning book");

txtMNo.setText("");

txtMName.setText("");

51 | P a g e
Library Management System
txtMDate.setText("");

txtMStatus.setText("");

txtAcno.setText("");

txtBTitle.setText("");

txtAuth.setText("");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}}

Return Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);

Member Form

52 | P a g e
Library Management System

Source Code:-
Window’s Gained Focus:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

cmdSave.setEnabled(false);

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

53 | P a g e
Library Management System
Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement s=(Statement) con.createStatement();

String sql="Select curdate() as D";

ResultSet r=s.executeQuery(sql);

if(r.next()){

txtMDate.setText(""+r.getString("D"));

r.close();

con.close();

s.close();

catch(Exception e){

New Button:-
private void cmdNewActionPerformed(java.awt.event.ActionEvent evt) {

cmdSave.setEnabled(true);

Calendar curdate=Calendar.getInstance();

txtMDate.setText(""+curdate.get(Calendar.YEAR)+"/"+curdate.get(Calendar.MONTH)
+"/"+curdate.get(Calendar.DATE));

String url="jdbc:mysql://localhost:3306/library";
54 | P a g e
Library Management System
try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

String SQL = "SELECT * FROM member";

stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(SQL);

int MNO=0, Mno = 0;

while (rs.next()) {

MNO = rs.getInt("memb_no");

MNO++;

Mno = MNO;

txtMNo.setText(Integer.toString(Mno));

txtMName.setFocusable(true);

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

Save Button:-
private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {

String url="jdbc:mysql://localhost:3306/library";

55 | P a g e
Library Management System
try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

String SQL = "SELECT * FROM publisher";

stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(SQL);

int Mno = Integer.parseInt(txtMNo.getText());

String MName = txtMName.getText();

String MAdd = txtMAdd.getText();

String MPh1 = txtMPh.getText();

String MDate = txtMDate.getText();

String MEDate = txtMDate.getText();

double MFee = Double.parseDouble(txtMFee.getText());

char status='N';

int code = JOptionPane.showConfirmDialog(this, "Are you sure to add?",


"Confirmation Dialog Box", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE);

if (code == JOptionPane.YES_OPTION) {

String strSQL = "INSERT INTO Member(memb_no, memb_name, memb_add,


memb_phone, mdate, medate, mfee,mem_issue) VALUES ("+(Mno)+", '"+(MName)+"', '"+
(MAdd)+"', '"+(MPh1)+"', '"+(MDate)+"', '"+(MEDate)+"', "+(MFee)+",'"+(status)+"')";

int rowsEffected = stmt.executeUpdate(strSQL);

56 | P a g e
Library Management System
JOptionPane.showMessageDialog(this, "Record added successfully into
Member table");

txtMNo.setText("");

txtMName.setText("");

txtMAdd.setText("");

txtMPh.setText("");

txtMFee.setText("");

cmdSave.setEnabled(false);

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}}

Clear Button:-
private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {

txtMNo.setText("");

txtMName.setText("");

txtMAdd.setText("");

txtMPh.setText("");

txtMDate.setText("");

txtMFee.setText("");

cmdSave.setEnabled(false);

57 | P a g e
Library Management System

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);

Member Edit Form

58 | P a g e
Library Management System

Source Code:-
Window’s Gained Focus:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

DefaultListModel dModel = (DefaultListModel) jList1.getModel();

dModel.clear();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM Member");

while (rs.next()) {

String Mno = rs.getString("memb_no");

String MName = rs.getString("memb_name");

dModel.addElement(Mno + "- " + MName);

jList1.setModel(dModel);

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

}}

Mouse Clicked:-
59 | P a g e
Library Management System
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

String MembNo = (String) jList1.getSelectedValue();

String Mno =MembNo.trim().substring(0, 3);

String query = "SELECT * FROM Member WHERE memb_no = " + (Mno) + ";";

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(query);

if (rs.next()) {

String MName = rs.getString("memb_name");

String MAdd = rs.getString("memb_add");

String MPh1 = rs.getString("memb_phone");

String MDate = rs.getString("mdate");

String MEDate = rs.getString("medate");

String MFee = rs.getString("mfee");

txtMNo.setText(Mno);

txtMName.setText(MName);

txtMAdd.setText(MAdd);

txtMPh.setText(MPh1);

txtMDate.setText(MDate);

txtMFee.setText(MFee);
60 | P a g e
Library Management System
} else {

JOptionPane.showMessageDialog(null, "Record does not found in Member


table");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}}

Update Button:-
private void cmdUpdateActionPerformed(java.awt.event.ActionEvent evt) {

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM Member");

int Mno = Integer.parseInt(txtMNo.getText().trim());

String MName = txtMName.getText();

String MAdd = txtMAdd.getText();

String MPh1 = txtMPh.getText();

61 | P a g e
Library Management System
String MDate = txtMDate.getText();

String MEDate = txtMDate.getText();

double MFee = Double.parseDouble(txtMFee.getText());

String strSQL = "Update Member set memb_name ='"+(MName)+"', memb_add


= '"+(MAdd)+"', memb_phone = '"

+(MPh1)+"', mdate = '"+(MDate)+"', mfee = "+(MFee)+" where memb_no = " +


(Mno);

stmt.executeUpdate(strSQL);

JOptionPane.showMessageDialog(null,"Record modified sucessfullys");

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

Delete Button:-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String url="jdbc:mysql://localhost:3306/library";

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=(Connection) DriverManager.getConnection(url,"root","");

Statement stmt=(Statement) con.createStatement();

String SQL = "SELECT * FROM member";

stmt = (Statement) con.createStatement();

62 | P a g e
Library Management System
ResultSet rs = stmt.executeQuery(SQL);

int pno = Integer.parseInt(txtMNo.getText().trim());

int opt = JOptionPane.showConfirmDialog(null, "Are you sure to delete this


record ?");

if (opt == JOptionPane.YES_OPTION)

try {

String strSQL = "Delete from member where Memb_no="+pno;

stmt.executeUpdate(strSQL);

JOptionPane.showMessageDialog(this,"Record Deleted");

txtMNo.setText("");

txtMName.setText("");

txtMAdd.setText("");

txtMPh.setText("");

txtMFee.setText("");

txtMDate.setText("");

} catch (Exception e) {

JOptionPane.showMessageDialog(null, "Unable to delete");

} }

} catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

63 | P a g e
Library Management System
}

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);

Avialable Books Form

64 | P a g e
Library Management System

Source Code:-
Window’s Gained Focus:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

DefaultTableModel model = (DefaultTableModel) jTable1.getModel();

int rows = model.getRowCount();

if (rows > 0) {

for (int i = 0; i < rows; i++) {

model.removeRow(0);

char st = 'Y'; // Lib table

String query = "SELECT * FROM Lib WHERE status = '" + st + "';";

try {

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next()) {

String Acno = rs.getString("acc_no");

String bTitle = rs.getString("btitle");

String Auth1 = rs.getString("author1");

65 | P a g e
Library Management System
String Price = rs.getString("price");

String edition = rs.getString("edition");

model.addRow(new Object[] {Acno, bTitle, Auth1, Price, edition});

catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}}

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);

Issued Books Form

66 | P a g e
Library Management System

Source Code:-
Window’s Gained Focus:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

DefaultTableModel model = (DefaultTableModel) jTable1.getModel();

int rows = model.getRowCount();

if (rows > 0) {

for (int i = 0; i < rows; i++) {

model.removeRow(0);

char st = 'N';

String query = "SELECT * FROM Lib WHERE status = '" + st + "';";


67 | P a g e
Library Management System
try {

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next()) {

String Acno = rs.getString("acc_no");

String bTitle = rs.getString("btitle");

String Auth1 = rs.getString("author1");

String Price = rs.getString("price");

String edition = rs.getString("edition");

model.addRow(new Object[] {Acno, bTitle, Auth1, Price, edition});

catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}}

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);

}
68 | P a g e
Library Management System

Member List Form

Source Code:-
Window’s Gained Focus:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

DefaultTableModel model = (DefaultTableModel) jTable1.getModel();

int rows = model.getRowCount();

if (rows > 0) {

for (int i = 0; i < rows; i++) {

model.removeRow(0);

69 | P a g e
Library Management System
}

String query = "SELECT * FROM Member";

try {

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next()) {

String Mno = rs.getString("memb_no");

String MName = rs.getString("memb_name");

String MAdd = rs.getString("memb_add");

String MPh1 = rs.getString("memb_phone");

String MDate = rs.getString("mdate");

model.addRow(new Object[] {Mno, MName, MAdd, MPh1, MDate});

catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}}

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {
70 | P a g e
Library Management System
this.setVisible(false);

new Main().setVisible(true);

71 | P a g e
Library Management System

Publisher List Form

Source Code:-
Window’s Gained Focus:-
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

DefaultTableModel model = (DefaultTableModel) jTable1.getModel();

int rows = model.getRowCount();

if (rows > 0) {

for (int i = 0; i < rows; i++) {

model.removeRow(0);

}
72 | P a g e
Library Management System

String query = "SELECT * FROM publisher;";

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","");

Statement stmt = (Statement) con.createStatement();

ResultSet rs = stmt.executeQuery(query);

while (rs.next()) {

String pubid = rs.getString("Pub_id");

String pname = rs.getString("Pub_name");

String padd = rs.getString("Pub_address");

String phone1 = rs.getString("Pub_phone1");

String phone2 = rs.getString("Pub_phone");

model.addRow(new Object[] {pubid, pname, padd, phone1, phone2});

catch (Exception e) {

JOptionPane.showMessageDialog(this, e.getMessage());

}
73 | P a g e
Library Management System
}

Exit Button:-
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new Main().setVisible(true);

74 | P a g e

You might also like