Develop business logic layer for Library Management System

CODE:-

Library.java

package pra3;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import javax.swing.GroupLayout.Alignment;

import javax.swing.LayoutStyle.ComponentPlacement;

import javax.swing.border.EmptyBorder;

public class Pra3 extends JFrame {

    static Pra3 frame;

    private JPanel contentPane;

    public static void main(String[] args) {

        EventQueue.invokeLater(new Runnable() {

public void run() {

try {

frame= new Pra3();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

    }

    public Pra3() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

JLabel lblLibraryManagement = new JLabel("Library Management");

lblLibraryManagement.setFont(new Font("Tahoma", Font.PLAIN, 18));

lblLibraryManagement.setForeground(Color.GRAY);

JButton btnAdminLogin = new JButton("Admin Login");

btnAdminLogin.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

AdminLogin.main(new String[]{});

frame.dispose();

}

});

btnAdminLogin.setFont(new Font("Tahoma", Font.PLAIN, 15));

JButton btnLibrarianLogin = new JButton("Librarian Login");

btnLibrarianLogin.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

LibrarianLogin.main(new String[]{});

}

});

btnLibrarianLogin.setFont(new Font("Tahoma", Font.PLAIN, 15));

GroupLayout gl_contentPane = new GroupLayout(contentPane);

gl_contentPane.setHorizontalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(64)

.addComponent(lblLibraryManagement))

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(140)

.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)

.addComponent(btnLibrarianLogin, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(btnAdminLogin, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))))

.addContainerGap(95, Short.MAX_VALUE))

);

gl_contentPane.setVerticalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addContainerGap()

.addComponent(lblLibraryManagement)

.addGap(32)

.addComponent(btnAdminLogin, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE)

.addPreferredGap(ComponentPlacement.UNRELATED)

.addComponent(btnLibrarianLogin, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)

.addContainerGap(70, Short.MAX_VALUE))

);

contentPane.setLayout(gl_contentPane);

}

}

AdminLogin.java

package pra3;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.GroupLayout;

import javax.swing.GroupLayout.Alignment;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import java.awt.Font;

import java.awt.Color;

import javax.swing.JTextField;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.JPasswordField;

public class AdminLogin extends JFrame {

static AdminLogin frame;

private JPanel contentPane;

private JTextField textField;

private JPasswordField passwordField;

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

frame = new AdminLogin();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

public AdminLogin() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

JLabel lblAdminLoginForm = new JLabel("Admin Login Form");

lblAdminLoginForm.setForeground(Color.GRAY);

lblAdminLoginForm.setFont(new Font("Tahoma", Font.PLAIN, 18));

JLabel lblEnterName = new JLabel("Enter Name:");

JLabel lblEnterPassword = new JLabel("Enter Password:");

textField = new JTextField();

textField.setColumns(10);

JButton btnLogin = new JButton("Login");

btnLogin.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String name=textField.getText();

String password=String.valueOf(passwordField.getPassword());

if(name.equals("Kiran")&&password.equals("admin123")){

AdminSuccess.main(new String[]{});

frame.dispose();

}else{

JOptionPane.showMessageDialog(AdminLogin.this, "Sorry, Username or Password Error","Login Error!", JOptionPane.ERROR_MESSAGE);

textField.setText("");

passwordField.setText("");

}

}

});

passwordField = new JPasswordField();

GroupLayout gl_contentPane = new GroupLayout(contentPane);

gl_contentPane.setHorizontalGroup(

gl_contentPane.createParallelGroup(Alignment.TRAILING)

.addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(124)

.addComponent(lblAdminLoginForm))

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(19) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)

.addComponent(lblEnterName)

.addComponent(lblEnterPassword))

.addGap(47) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)

.addComponent(passwordField)

.addComponent(textField, GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))))

.addContainerGap(107, Short.MAX_VALUE))

.addGroup(gl_contentPane.createSequentialGroup()

.addContainerGap(187, Short.MAX_VALUE)

.addComponent(btnLogin, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE)

.addGap(151))

);

gl_contentPane.setVerticalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addComponent(lblAdminLoginForm)

.addGap(26) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(lblEnterName)

.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))

.addGap(28)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(lblEnterPassword)

.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))

.addGap(18)

.addComponent(btnLogin, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)

.addContainerGap(80, Short.MAX_VALUE))

);

contentPane.setLayout(gl_contentPane);

}

}

AdminSuccess.java

package pra3;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.GroupLayout;

import javax.swing.GroupLayout.Alignment;

import javax.swing.JLabel;

import java.awt.Color;

import java.awt.Font;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.LayoutStyle.ComponentPlacement;

import java.sql.*;

public class AdminSuccess extends JFrame {

static AdminSuccess frame;

private JPanel contentPane;

 

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

frame = new AdminSuccess();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

public AdminSuccess() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 371);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

JLabel lblAdminSection = new JLabel("Admin Section");

lblAdminSection.setFont(new Font("Tahoma", Font.PLAIN, 22));

lblAdminSection.setForeground(Color.GRAY);

JButton btnNewButton = new JButton("Add Librarian");

btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 15));

btnNewButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

LibrarianForm.main(new String[]{});

frame.dispose();

}

});

JButton btnViewLibrarian = new JButton("View Librarian");

btnViewLibrarian.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

ViewLibrarian.main(new String[]{});

}

});

btnViewLibrarian.setFont(new Font("Tahoma", Font.PLAIN, 15));

JButton btnDeleteLibrarian = new JButton("Delete Librarian");

btnDeleteLibrarian.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

DeleteLibrarian.main(new String[]{});

frame.dispose();

}

});

btnDeleteLibrarian.setFont(new Font("Tahoma", Font.PLAIN, 15));

JButton btnLogout = new JButton("Logout");

btnLogout.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

Pra3.main(new String[]{});

frame.dispose();

}

});

btnLogout.setFont(new Font("Tahoma", Font.PLAIN, 15));

GroupLayout gl_contentPane = new GroupLayout(contentPane);

gl_contentPane.setHorizontalGroup(

gl_contentPane.createParallelGroup(Alignment.TRAILING)

.addGroup(gl_contentPane.createSequentialGroup()

.addContainerGap(150, Short.MAX_VALUE)

.addComponent(lblAdminSection, GroupLayout.PREFERRED_SIZE, 151, GroupLayout.PREFERRED_SIZE)

.addGap(123))

.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()

.addGap(134)

.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)

.addComponent(btnLogout, GroupLayout.PREFERRED_SIZE, 181, GroupLayout.PREFERRED_SIZE)

.addComponent(btnDeleteLibrarian, GroupLayout.PREFERRED_SIZE, 181, GroupLayout.PREFERRED_SIZE)

.addComponent(btnViewLibrarian, GroupLayout.PREFERRED_SIZE, 181, GroupLayout.PREFERRED_SIZE)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 181, GroupLayout.PREFERRED_SIZE))

.addContainerGap(109, Short.MAX_VALUE))

);

gl_contentPane.setVerticalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addComponent(lblAdminSection, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)

.addGap(11)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)

.addGap(18)

.addComponent(btnViewLibrarian, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)

.addGap(18)

.addComponent(btnDeleteLibrarian, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)

.addGap(18)

.addComponent(btnLogout, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)

.addContainerGap(21, Short.MAX_VALUE))

);

contentPane.setLayout(gl_contentPane);

}

}

LibrarianForm.java

package pra3;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.GroupLayout;

import javax.swing.GroupLayout.Alignment;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import java.awt.Font;

import java.awt.Color;

import javax.swing.JTextField;

import javax.swing.JPasswordField;

import javax.swing.LayoutStyle.ComponentPlacement;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class LibrarianForm extends JFrame {

static LibrarianForm frame;

private JPanel contentPane;

private JTextField textField;

        private JTextField textField2;

private JTextField textField_1;

private JTextField textField_2;

private JTextField textField_3;

private JTextField textField_4;

private JPasswordField passwordField;

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

frame = new LibrarianForm();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

public LibrarianForm() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 450);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

JLabel lblAddLibrarian = new JLabel("Add Librarian");

lblAddLibrarian.setForeground(Color.DARK_GRAY);

lblAddLibrarian.setFont(new Font("Tahoma", Font.PLAIN, 22));

                JLabel lblId = new JLabel("ID:");

                

JLabel lblName = new JLabel("Name:");

JLabel lblPassword = new JLabel("Password:");

JLabel lblEmail = new JLabel("Email:");

JLabel lblAddress = new JLabel("Address:");

JLabel lblCity = new JLabel("City:");

JLabel lblContactNo = new JLabel("Contact No:");

                textField2 = new JTextField();

textField2.setColumns(10);

                

textField = new JTextField();

textField.setColumns(10);

textField_1 = new JTextField();

textField_1.setColumns(10);

textField_2 = new JTextField();

textField_2.setColumns(10);

textField_3 = new JTextField();

textField_3.setColumns(10);

textField_4 = new JTextField();

textField_4.setColumns(10);

passwordField = new JPasswordField();

JButton btnNewButton = new JButton("Add Librarian");

btnNewButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

                        String idn = textField2.getText();

String name=textField.getText();

String password=String.valueOf(passwordField.getPassword());

String email=textField_1.getText();

String address=textField_2.getText();

String city=textField_3.getText();

String contact=textField_4.getText();

 

int i=LibrarianDao.save(idn,name, password, email, address, city, contact);

if(i>0){

JOptionPane.showMessageDialog(LibrarianForm.this,"Librarian added successfully!");

AdminSuccess.main(new String[]{});

frame.dispose();

}else{

JOptionPane.showMessageDialog(LibrarianForm.this,"Sorry, unable to save!");

}

}

});

btnNewButton.setForeground(Color.DARK_GRAY);

JButton btnBack = new JButton("Back");

btnBack.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

AdminSuccess.main(new String[]{});

frame.dispose();

}

});

GroupLayout gl_contentPane = new GroupLayout(contentPane);

gl_contentPane.setHorizontalGroup(

gl_contentPane.createParallelGroup(Alignment.TRAILING)

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(20)

.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)

.addComponent(lblPassword, GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)                                               

.addComponent(lblName)

                                                .addComponent(lblId, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)

.addComponent(lblEmail, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)

.addComponent(lblAddress, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(lblCity, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)

.addComponent(lblContactNo, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addGap(58) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)

.addComponent(textField_4, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)

.addComponent(textField_3, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)

.addComponent(textField_2, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)

.addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)

.addComponent(textField, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)

                                                .addComponent(textField2, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)

.addComponent(passwordField))

.addContainerGap(107, Short.MAX_VALUE))

.addGroup(gl_contentPane.createSequentialGroup()

.addContainerGap(151, Short.MAX_VALUE)

.addComponent(lblAddLibrarian)

.addGap(144))

.addGroup(gl_contentPane.createSequentialGroup()

.addContainerGap(160, Short.MAX_VALUE)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)

.addGap(133))

.addGroup(gl_contentPane.createSequentialGroup()

.addContainerGap(200, Short.MAX_VALUE)

.addComponent(btnBack)

.addGap(169))

);

gl_contentPane.setVerticalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addComponent(lblAddLibrarian)

.addGap(18)

.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

                                                        .addComponent(lblId)

.addGap(18)

.addComponent(lblName)

.addGap(18)

.addComponent(lblPassword))

.addGroup(gl_contentPane.createSequentialGroup()

                                                        .addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)

.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)

.addPreferredGap(ComponentPlacement.UNRELATED)

.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))

.addGap(18)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(lblEmail)

.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))

.addGap(18)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(lblAddress)

.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))

.addGap(18)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(lblCity)

.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))

.addGap(18)

.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)

.addComponent(lblContactNo)

.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))

.addGap(18)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)

.addPreferredGap(ComponentPlacement.RELATED, 57, Short.MAX_VALUE)

.addComponent(btnBack)

.addGap(19))

);

contentPane.setLayout(gl_contentPane);

}

 

}

 

LibrarianDao.java(DATABASE Connectivity)

package pra3;

import java.sql.*;

public class LibrarianDao {

    static final String JdbcDr = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

    static final String url = "jdbc:sqlserver://localhost:1433;databaseName=kiran";

    static final String user = "sa";

    static final String pass = "123456";

    

public static int save(String idn,String name,String password,String email,String address,String city,String contact){

int status=0;

try{

                        Class.forName(JdbcDr);

                    try (Connection con = DriverManager.getConnection(url,user,pass)) {

                        PreparedStatement ps=con.prepareStatement("insert into librarian(id,name,password,email,address,city,contact) values(?,?,?,?,?,?,?)");

                        ps.setString(1,idn);

                        ps.setString(2,name);

                        ps.setString(3,password);

                        ps.setString(4,email);

                        ps.setString(5,address);

                        ps.setString(6,city);

                        ps.setString(7,contact);

                        status=ps.executeUpdate();

                    }

}catch(Exception e){System.out.println(e);}

return status;

}

public static int delete(int id){

int status=0;

try{

Connection con=DriverManager.getConnection(url,user,pass);

PreparedStatement ps=con.prepareStatement("delete from librarian where id=?");

ps.setInt(1,id);

status=ps.executeUpdate();

con.close();

}catch(Exception e){System.out.println(e);}

return status;

}

 

public static boolean validate(String name,String password){

boolean status=false;

try{

Connection con=DriverManager.getConnection(url,user,pass);

PreparedStatement ps=con.prepareStatement("select * from librarian where name=? and password=?");

ps.setString(1,name);

ps.setString(2,password);

ResultSet rs=ps.executeQuery();

status=rs.next();

con.close();

}catch(Exception e){System.out.println(e);}

return status;

}

}

ViewLibrarian.java

package pra3;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.border.EmptyBorder;

import javax.swing.JTable;

import static pra3.LibrarianDao.JdbcDr;

public class ViewLibrarian extends JFrame {

private JPanel contentPane;

private JTable table;

        static final String JdbcDr = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

        static final String url = "jdbc:sqlserver://localhost:1433;databaseName=kiran";

        static final String user = "sa";

        static final String pass = "123456";

 

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

ViewLibrarian frame = new ViewLibrarian();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

public ViewLibrarian() {

setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

contentPane.setLayout(new BorderLayout(0, 0));

setContentPane(contentPane);

String data[][]=null;

String column[]=null;

                

try{

                        Class.forName(JdbcDr);

                    try (Connection con = DriverManager.getConnection(url,user,pass)) {

                        PreparedStatement ps=con.prepareStatement("select * from librarian",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

                        ResultSet rs=ps.executeQuery();

                        

                        ResultSetMetaData rsmd=rs.getMetaData();

                        int cols=rsmd.getColumnCount();

                        column=new String[cols];

                        for(int i=1;i<=cols;i++){

                            column[i-1]=rsmd.getColumnName(i);

                        }

                        

                        rs.last();

                        int rows=rs.getRow();

                        rs.beforeFirst();

                        

                        data=new String[rows][cols];

                        int count=0;

                        while(rs.next()){

                            for(int i=1;i<=cols;i++){

                                data[count][i-1]=rs.getString(i);

                            }

                            count++;

                        }

                    }

}catch(Exception e){System.out.println(e);}

table = new JTable(data,column);

JScrollPane sp=new JScrollPane(table);

contentPane.add(sp, BorderLayout.CENTER);

}

}

 

DeleteLibrarian.java

package pra3;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.GroupLayout;

import javax.swing.GroupLayout.Alignment;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

import javax.swing.JButton;

import java.awt.Font;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class DeleteLibrarian extends JFrame {

static DeleteLibrarian frame;

private JPanel contentPane;

private JTextField textField;

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

frame = new DeleteLibrarian();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

public DeleteLibrarian() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

JLabel lblEnterId = new JLabel("Enter Id:");

textField = new JTextField();

textField.setColumns(10);

JButton btnDelete = new JButton("Delete");

btnDelete.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String sid=textField.getText();

if(sid==null||sid.trim().equals("")){

JOptionPane.showMessageDialog(DeleteLibrarian.this,"Id can't be blank");

}else{

int id=Integer.parseInt(sid);

int i=LibrarianDao.delete(id);

if(i>0){

JOptionPane.showMessageDialog(DeleteLibrarian.this,"Record deleted successfully!");

}else{

JOptionPane.showMessageDialog(DeleteLibrarian.this,"Unable to delete given id!");

}

}

}

});

btnDelete.setFont(new Font("Tahoma", Font.PLAIN, 13));

JButton btnNewButton = new JButton("Back");

btnNewButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

AdminSuccess.main(new String[]{});

frame.dispose();

}

});

btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 13));

GroupLayout gl_contentPane = new GroupLayout(contentPane);

gl_contentPane.setHorizontalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(39)

.addComponent(lblEnterId)

.addGap(57)

.addComponent(textField, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE)

.addContainerGap(107, Short.MAX_VALUE))

.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()

.addContainerGap(175, Short.MAX_VALUE)

.addComponent(btnDelete, GroupLayout.PREFERRED_SIZE, 109, GroupLayout.PREFERRED_SIZE)

.addGap(140))

.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()

.addContainerGap(322, Short.MAX_VALUE)

.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 92, GroupLayout.PREFERRED_SIZE)

.addContainerGap())

);

gl_contentPane.setVerticalGroup(

gl_contentPane.createParallelGroup(Alignment.LEADING)

.addGroup(gl_contentPane.createSequentialGroup()

.addGap(19)

.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)

.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)

.addComponent(lblEnterId))

.addGap(33)

.addComponent(btnDelete, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)

.addGap(43)

.addComponent(btnNewButton)

.addContainerGap(78, Short.MAX_VALUE))



);

contentPane.setLayout(gl_contentPane);

}

}

output:

Develop business logic layer for Library Management System
Develop business logic layer for Library Management System


Develop business logic layer for Library Management System


Develop business logic layer for Library Management System


Develop business logic layer for Library Management System


Develop business logic layer for Library Management System


Develop business logic layer for Library Management System


Develop business logic layer for Library Management System


Develop business logic layer for Library Management System


Develop business logic layer for Library Management System


Develop business logic layer for Library Management System
















Post a Comment

0 Comments