0% found this document useful (0 votes)
51 views12 pages

Package Bookbank

1. The document describes a Java program for a book bank management system with classes like Bookbank, Index, Search, Issue, and Return. 2. The Bookbank class handles user login authentication from a database and opens the index frame. 3. The index frame allows searching for book details, issuing books to users, and returning books with the Search, Issue, and Return classes respectively.

Uploaded by

jayashreedivya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views12 pages

Package Bookbank

1. The document describes a Java program for a book bank management system with classes like Bookbank, Index, Search, Issue, and Return. 2. The Bookbank class handles user login authentication from a database and opens the index frame. 3. The index frame allows searching for book details, issuing books to users, and returning books with the Search, Issue, and Return classes respectively.

Uploaded by

jayashreedivya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

CODING: package bookbank; import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.

*; class Bookbank implements ActionListener { JButton b1,b2; static JFrame f1; JPanel p; JLabel l1,l2; JTextField t1; JPasswordField t2; static ResultSet r; static Connection conn; static Statement stat; static int i; static Bookbank bb1; static String n1,p1; static String uname[]=new String[100]; static String pword[]=new String[100]; Bookbank() { f1=new JFrame("Bookbank Login Form"); p=new JPanel(new GridLayout(5,5)); b1=new JButton("SIGN IN"); b2=new JButton("EXIT"); l1=new JLabel(); l1.setText("User Name:"); l2=new JLabel(); l2.setText("Password:"); t1=new JTextField(10); t2=new JPasswordField(10); p.add(l1); p.add(t1); p.add(l2); p.add(t2); p.add(b1); p.add(b2); f1.add(p); f1.setSize(300,200); f1.setVisible(true); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); b1.addActionListener(this);

b2.addActionListener(this); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:Bookbank"); // cust is the DSN Name stat = conn.createStatement(); r = stat.executeQuery("Select * from loginbb;"); i=0; while(r.next()) { uname[i]=r.getString(1); pword[i]=r.getString(2); i++; } } catch(Exception e) { System.out.println("Error" +e); } } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) { try { String u=t1.getText(); String p=t2.getText(); for(i=0;i<uname.length;i++) { if((uname[i].equals(u))&&(pword[i].equals(p))) { index in=new index(); f1.setVisible(false); break; } else continue; } } catch(Exception e) { System.out.println("Error" +e); JOptionPane.showMessageDialog(f1,"Error : Incorrect login or password","Login Error",JOptionPane.ERROR_MESSAGE); }

} else { f1.setVisible(false); System.exit(1); } } public static void main(String args[]) { bb1=new Bookbank(); } } class index implements ActionListener { JFrame f2; JPanel p1; JButton sb,ib,rb,ex; index() { f2=new JFrame("Bookbank Index"); sb=new JButton("SEARCH BOOKS"); sb.addActionListener(this); ib=new JButton("ISSUE BOOKS"); ib.addActionListener(this); rb=new JButton("RETURN BOOKS"); rb.addActionListener(this); ex=new JButton("EXIT"); ex.addActionListener(this); p1=new JPanel(new BorderLayout()); f2.setSize(300,300); f2.setVisible(true); p1.add(sb,BorderLayout.NORTH); p1.add(ib,BorderLayout.WEST); p1.add(rb,BorderLayout.EAST); p1.add(ex,BorderLayout.SOUTH); f2.add(p1); f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==sb) { search s=new search(); } else if(ae.getSource()==ib) {

issue i=new issue(); } else if(ae.getSource()==rb) { ret r=new ret(); } else System.exit(1); } } class search implements ActionListener { JFrame f3; JPanel p,p1; JLabel l1,l2,l3,l4,l5,l6; JComboBox t1; JTextField t2,t3,t4,t5,t6; JButton b1,b2,b3,b4; static ResultSet r2; static Connection conn2; static Statement stat2; int i; static String id[]=new String[100]; static String bookname[]=new String[100]; static String author[]=new String[100]; static String edition[]=new String[100]; static String publication[]=new String[100]; static String quantity[]=new String[100]; public search() { f3=new JFrame("Book details"); p=new JPanel(); p.setLayout(new GridLayout(8,8,5,5)); p1=new JPanel(); p1.setLayout(new BorderLayout()); b1=new JButton("SHOW DETAILS"); b2=new JButton("BACK"); l1=new JLabel("Book Name:"); l2=new JLabel("Book id."); l3=new JLabel("Author"); l4=new JLabel("Edition"); l5=new JLabel("Publication"); l6=new JLabel("Quantity:"); t1=new JComboBox(); t2=new JTextField(10);

t3=new JTextField(10); t4=new JTextField(10); t5=new JTextField(10); t6=new JTextField(10); p.add(l1); p.add(t1); p.add(b1); p.add(b2); p.add(l2); p.add(t2); p.add(l3); p.add(t3); p.add(l4); p.add(t4); p.add(l5); p.add(t5); p.add(l6); p.add(t6); //p1.add(h,BorderLayout.NORTH); p1.add(p,BorderLayout.CENTER); f3.add(p1); f3.setSize(400,400); f3.setVisible(true); f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); b1.addActionListener(this); b2.addActionListener(this); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn2 = DriverManager.getConnection("jdbc:odbc:Bookbank"); stat2 = conn2.createStatement(); r2 = stat2.executeQuery("Select * from Book"); i=0; while(r2.next()) { id[i]=r2.getString(1); bookname[i]=r2.getString(2); author[i]=r2.getString(3); edition[i]=r2.getString(4); publication[i]=r2.getString(5); quantity[i]=r2.getString(6); i++; } for(i=0;i<bookname.length;i++) { t1.addItem(bookname[i]);

} } catch(Exception e) { System.out.println("Error:" +e); } } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) { try { for(i=0;i<bookname.length;i++) { if(bookname[i].equals(t1.getSelectedItem())) { t2.setText(id[i]); t3.setText(author[i]); t4.setText(edition[i]); t5.setText(publication[i]); t6.setText(quantity[i]); break; } else continue; } } catch(Exception e) { System.out.println("Error" +e); JOptionPane.showMessageDialog(f3,"Error : Enter the correct name","Error",JOptionPane.ERROR_MESSAGE); } } else { f3.setVisible(false); index in=new index(); } } public static void main(String ar[]) { Bookbank a1=new Bookbank(); } }

class issue implements ActionListener { JFrame f4; JPanel p1; JLabel l1,l2; JButton b1,b2; JTextField t1,t2; static ResultSet r3; static Connection conn3; static Statement stat3; int i; static String bookname[]=new String[100]; static String quantity[]=new String[100]; static String uname[]=new String[100]; static String bname[]=new String[100]; static String noofbooks[]=new String[100]; issue() { f4=new JFrame(); p1=new JPanel(new GridLayout(3,3,5,5)); l1=new JLabel("enter Name:"); l2=new JLabel("enter bookname:"); t1=new JTextField(10); t2=new JTextField(10); b1=new JButton("CONFIRM ISSUE"); b2=new JButton("BACK"); p1.add(l1); p1.add(t1); p1.add(l2); p1.add(t2); p1.add(b1); p1.add(b2); f4.add(p1); f4.setSize(400,200); f4.setVisible(true); f4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); b1.addActionListener(this); b2.addActionListener(this); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn3 = DriverManager.getConnection("jdbc:odbc:Bookbank"); stat3 = conn3.createStatement(); r3 = stat3.executeQuery("Select * from Book");

i=0; while(r3.next()) { bookname[i]=r3.getString(2); quantity[i]=r3.getString(6); i++; } } catch(Exception e) { System.out.println("Error:" +e); } } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) { try { for(i=0;i<bookname.length;i++) { if(bookname[i].equals(t2.getText())) { int no=Integer.parseInt(quantity[i]); no=no-1; if(no>0) { f4.setVisible(false); try { conn3 = DriverManager.getConnection("jdbc:odbc:Bookbank"); stat3 = conn3.createStatement(); r3 = stat3.executeQuery("update Book set quantity='"+no+"' where bookname='"+t2.getText()+"'"); stat3 = conn3.createStatement(); r3 = stat3.executeQuery("insert into user values ('"+t1.getText()+"','"+t2.getText()+"','"+1+"')"); } catch(Exception e) { System.out.println("Error:"+e); } JOptionPane.showMessageDialog(f4,"issued Successful","Thank You.",JOptionPane.INFORMATION_MESSAGE); break;

} else {JOptionPane.showMessageDialog(f4,"Error :now books are not available","Error",JOptionPane.ERROR_MESSAGE); break;} } else continue; } } catch(Exception e) { System.out.println("Error" +e); JOptionPane.showMessageDialog(f4,"Error : Enter the correct book name","Error",JOptionPane.ERROR_MESSAGE); } } else { f4.setVisible(false); index in=new index(); } } } class ret implements ActionListener { JFrame f5; JPanel p1; JLabel l1,l2; JButton b1,b2; JTextField t1,t2; static ResultSet r3; static Connection conn3; static Statement stat3; int i; static String bookname[]=new String[100]; static String quantity[]=new String[100]; static String uname[]=new String[100]; static String bname[]=new String[100]; static String noofbooks[]=new String[100]; ret() { f5=new JFrame(); p1=new JPanel(new GridLayout(3,3,5,5)); l1=new JLabel("Enter st_name:");

l2=new JLabel("Enter bookname:"); t1=new JTextField(10); t2=new JTextField(10); b1=new JButton("CONFIRM RETURN"); b2=new JButton("BACK"); p1.add(l1); p1.add(t1); p1.add(l2); p1.add(t2); p1.add(b1); p1.add(b2); f5.add(p1); f5.setSize(400,200); f5.setVisible(true); f5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); b1.addActionListener(this); b2.addActionListener(this); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn3 = DriverManager.getConnection("jdbc:odbc:Bookbank"); stat3 = conn3.createStatement(); r3 = stat3.executeQuery("Select * from user"); i=0; while(r3.next()) { uname[i]=r3.getString(1); bname[i]=r3.getString(2); noofbooks[i]=r3.getString(3); i++; } } catch(Exception e) { System.out.println("Error:" +e); } try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn3 = DriverManager.getConnection("jdbc:odbc:Bookbank"); stat3 = conn3.createStatement(); r3 = stat3.executeQuery("Select * from Book"); i=0; while(r3.next()) { bookname[i]=r3.getString(2);

quantity[i]=r3.getString(6); i++; } } catch(Exception e) { System.out.println("Error:" +e); } } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) { try { for(i=0;i<bookname.length;i++) { if(bookname[i].equals(t2.getText())) { for(int j=0;j<uname.length;j++) { if(uname[j].equals(t1.getText())) { int no=Integer.parseInt(quantity[i]); no=no+1; if(no>0) { f5.setVisible(false); try {conn3 = DriverManager.getConnection("jdbc:odbc:Bookabank"); stat3 = conn3.createStatement(); r3 = stat3.executeQuery("update Book set quantity='"+no+"' where bookname='"+t2.getText()+"'"); stat3 = conn3.createStatement(); r3 = stat3.executeQuery("insert into user values ('"+t1.getText()+"','"+t2.getText()+"','"+1+"')"); } catch(Exception e) {System.out.println("Error:"+e);} JOptionPane.showMessageDialog(f5,"returned Successful","ThankYou.",JOptionPane.INFORMATION_MESSAGE); break;} else { }} } }}}

catch(Exception e) { } } else { f5.setVisible(false); index in=new index(); } } }

You might also like