Hospital Management System using core Java

In this tutorial, we will learn to make a Java project ie. HOSPITAL MANAGEMENT SYSTEM. Many college or school students want to make attractive projects but due to insufficient knowledge are not able to make the project as desired.

so in this tutorial, we will learn to make the project from scratch.

For creating a java project we can use notepad, eclipse, Netbeans, etc.

It is very easy for us to make the project without a graphical user interface, but in this tutorial, we will learn to make the project using the graphical user interface.

As we all know a project consists of front end and backend.  For Frontend we will use swings. And For Backend, we will use core java concepts ie. JDBC(Java database connectivity), packages, etc.

HOSPITAL MANAGEMENT SYSTEM as the name suggests is the software that manages the working of hospitals.

operations that we can perform using project

1. First of all, we will receive a login form in which we can either log in as staff or a doctor by adding username and password.

2. If entered username or password is correct then we will receive a dialogue box welcome staff or welcome doctor. clicking ok on dialogue box will lead us to the staff or doctor’s dashboard. If the username or password is incorrect we will receive a dialogue box Invalid username or password.

3. At the staff dashboard, we will receive several operations for example: ADD STAFF, ADD DOCTOR, PREPARE BILL, ADD PATIENT, ADD TEST, APPOINTMENT, VIEW DOCTOR, UPDATE DOCTOR, BILL, VIEW DOCTOR, VIEW STAFF, VIEW PATIENT, UPDATE PATIENT, etc.

4. At the doctor’s dashboard, we will receive other options like ADD TEST, ADD PATIENT, VIEW TEST, VIEW PATIENTS, etc.

5. There will be one java page for the connection of Netbeans with Mysql.

All the data entered will be stored in the form of tables using MySQL.

 

package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class hmsproject extends javax.swing.JFrame {
 public hmsproject() {
        initComponents();
    }
@SuppressWarnings("unchecked")
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         
        try{
            Connection con=Connectiondb.getConnection();
            PreparedStatement ps=null;
            if(staffr.isSelected()){
                ps=con.prepareStatement("select * from staff where uname=? and pwd=?");
                ps.setString(1,namer.getText());
                 ps.setString(2,pwd.getText());
                ResultSet rs=ps.executeQuery();
                if(rs.next()){
                      JOptionPane.showMessageDialog(null, "Welcome STAFF");
                    Staffdashboard sd = new Staffdashboard();
                    sd.setVisible(true);        //to open new frame ad
                    this.dispose();
                }
                else
                {
                    //invalid admin
                    JOptionPane.showMessageDialog(null, "Invalid Uname or Password");
                    hmsproject hms = new hmsproject();
                    hms.setVisible(true);        //to open new frame ad
                    this.dispose();             //to close current frame
                }
                    
                
            }
              else if(doctorr.isSelected())    
            {
                
                ps = con.prepareStatement
                    ("select * from doctor where uname=? and pwd=?");
                ps.setString(1, namer.getText());
                ps.setString(2, pwd.getText());
                ResultSet rs=ps.executeQuery();
                if(rs.next())
                {   
                    JOptionPane.showMessageDialog(null,"welocome DOCTOR");
                    Doctordashboard td =new Doctordashboard();
                    td.setVisible(true);
                    this.dispose();
                    
                }
                else
                {  
                    JOptionPane.showMessageDialog(null,"Invalid username and password");
                    hmsproject hms = new hmsproject();
                    hms.setVisible(true);
                    this.dispose();
                    
                }
                
                
            }
   
        }  catch(Exception e)
        {
            System.out.println(e);
        }
 public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new hmsproject().setVisible(true);
            }
        });
    }
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JRadioButton doctorr;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField namer;
    private javax.swing.JPasswordField pwd;
    private javax.swing.JRadioButton staffr;
                       
}
    ------------------------------------------------------------------------------------------------------------------------------    
Addpatient.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.swing.JOptionPane;

public class Addpatient extends javax.swing.JFrame {
public Addpatient() {
        initComponents();
    }

   
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        name1 = new javax.swing.JTextField();
        age1 = new javax.swing.JTextField();
        disease = new javax.swing.JTextField();
        phone_number = new javax.swing.JTextField();
        guardian = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        uname = new javax.swing.JTextField();
        pwd = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("ADD NEW PATIENT");

        jLabel2.setText("NAME ");

        jLabel3.setText("AGE");

        jLabel4.setText("DISEASE");

        jLabel5.setText("PHONE NUMBER");

        jLabel6.setText("GUARDIAN");

        age1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                age1ActionPerformed(evt);
            }
        });

        disease.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diseaseActionPerformed(evt);
            }
        });

        guardian.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardianActionPerformed(evt);
            }
        });

        jButton1.setText("SUBMIT");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("CLEAR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel7.setText("uname");

        jLabel8.setText("password");

        


    private void age1ActionPerformed(java.awt.event.ActionEvent evt) {                                     
        
    }                                    

    private void guardianActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
    }                                        

    private void diseaseActionPerformed(java.awt.event.ActionEvent evt) {                                        
        
    }                                       

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         try {
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement("insert into patient(name1,age1,disease,phone_number,guardian,uname,pwd) values(?,?,?,?,?,?,?)");
            ps.setString(1, name1.getText());
            ps.setString(2, age1.getText());
            ps.setString(3, disease.getText());
            ps.setString(4, phone_number.getText());
            ps.setString(5, guardian.getText());
            ps.setString(6, uname.getText());
            ps.setString(7, pwd.getText());
            int x = ps.executeUpdate();
            if (x > 0) {
                JOptionPane.showMessageDialog(null, "Patient Added");
                Addpatient ap = new Addpatient();
                ap.setVisible(true);
                this.dispose();
            }
        } catch (Exception e) {
            System.out.println(e);
        }
        
        
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
name1.setText(" ");
age1.setText(" ");
disease.setText(" ");
phone_number.setText(" ");
guardian.setText(" ");

    }                                        

  
    public static void main(String args[]) {
       
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch Exception ex) ({
            java.util.logging.Logger.getLogger(Addpatient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Addpatient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Addpatient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Addpatient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Addpatient().setVisible(true);
            }
        });
    }

                       
    private javax.swing.JTextField age1;
    private javax.swing.JTextField disease;
    private javax.swing.JTextField guardian;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField name1;
    private javax.swing.JTextField phone_number;
    private javax.swing.JTextField pwd;
    private javax.swing.JTextField uname;
                       
}
--------------------------------------------------------------------------------------------------------------------
Addstaff.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.swing.JOptionPane;
public class Addstaff extends javax.swing.JFrame {

    public Addstaff() {
        initComponents();
    }

  
    @SuppressWarnings("unchecked")
    >                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        name = new javax.swing.JTextField();
        age = new javax.swing.JTextField();
        qualification = new javax.swing.JTextField();
        address = new javax.swing.JTextField();
        phone = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        pwd = new javax.swing.JPasswordField();
        uname = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("ADD NEW STAFF");

        jLabel2.setText("NAME");

        jLabel3.setText("AGE");

        jLabel4.setText("QUALIFICATION");

        jLabel5.setText("ADDRESS");

        jLabel6.setText("PHONE");

        jButton1.setText("SUBMIT");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("CLEAR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel7.setText("uname ");

        jLabel8.setText("password");

        pwd.setText("jPasswordField1");

   >                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement("insert into staff(name,age,qualification,address,phone,uname,pwd) values(?,?,?,?,?,?,?)");
            ps.setString(1, name.getText());
            ps.setString(2, age.getText());
            ps.setString(3, qualification.getText());
            ps.setString(4, address.getText());
            ps.setString(5, phone.getText());
            ps.setString(6, uname.getText());
            ps.setString(7, pwd.getText());
            int x = ps.executeUpdate();
            if (x > 0) {
                JOptionPane.showMessageDialog(null, "Staff Added");
                Addstaff as = new Addstaff();
                as.setVisible(true);
                this.dispose();
            }
        } catch (Exception e) {
            System.out.println(e);
        }
        
        
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
name.setText(" ");
age.setText(" ");
qualification.setText(" ");
address.setText(" ");
phone.setText(" ");
uname.setText(" ");
pwd.setText(" ");
    }                                        

    public static void main(String args[]) {
       
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Addstaff.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Addstaff.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Addstaff.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Addstaff.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
     
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Addstaff().setVisible(true);
            }
        });
    }

                        
    private javax.swing.JTextField address;
    private javax.swing.JTextField age;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField name;
    private javax.swing.JTextField phone;
    private javax.swing.JPasswordField pwd;
    private javax.swing.JTextField qualification;
    private javax.swing.JTextField uname;
                      
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
Addtest.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.swing.JOptionPane;
public class Addtest extends javax.swing.JFrame {

    public Addtest() {
        initComponents();
    }

 
    @SuppressWarnings("unchecked")
    >                          
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        DOOCTOR = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        name1 = new javax.swing.JTextField();
        fees = new javax.swing.JTextField();
        desc1 = new javax.swing.JTextField();
        doct = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("ADD NEW TEST");

        jLabel2.setText("TEST NAME");

        jLabel3.setText("TEST FEES");

        jLabel4.setText("DESCRIPTION");

        DOOCTOR.setText("DOCTOR");

        jButton1.setText("SAVE");
        buttonGroup1.add(jButton1);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("CLEAR");
        buttonGroup1.add(jButton2);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        desc1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                desc1ActionPerformed(evt);
            }
        });

                          

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          try {
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement("insert into test(name1,fees,desc1,doct) values(?,?,?,?)");
            ps.setString(1, name1.getText());
            ps.setString(2, fees.getText());
            ps.setString(3, desc1.getText());
            ps.setString(4, doct.getText());
            
            int x = ps.executeUpdate();
            if (x > 0) {
                JOptionPane.showMessageDialog(null, "TEST Added");
                Adddoctor ad = new Adddoctor();
                ad.setVisible(true);
                this.dispose();
            }
        } catch (Exception e) {
            System.out.println(e);
        }
        
        
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      name1.setText(" ");
      fees.setText(" ");
      desc1.setText(" ");
      doct.setText(" ");
    }                                        

    private void desc1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        
    }                                     

    
    public static void main(String args[]) {
     
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Addtest().setVisible(true);
            }
        });
    }

                         
    private javax.swing.JLabel DOOCTOR;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField desc1;
    private javax.swing.JTextField doct;
    private javax.swing.JTextField fees;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField name1;
                       
}
---------------------------------------------------------------------------------------------------------------------------------------------------------
Appointment.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;


public class Appointment extends javax.swing.JFrame {

  
    public Appointment() {
        initComponents();
    }

    
    @SuppressWarnings("unchecked")
                            
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        name = new javax.swing.JTextField();
        dname = new javax.swing.JTextField();
        page = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("appointment");

        jLabel2.setText("patient's name");

        jLabel3.setText("doctor's name");

        jLabel4.setText("patient's age");

        jLabel6.setText(" will text you the timings of appointment as soon as possible ");

        jButton1.setText("submit");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

                              

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement("insert into appointment(name,dname,page,date) values(?,?,?,?)");
            ps.setString(1, name.getText());
            ps.setString(2, dname.getText());
            ps.setString(3, page.getText());
            
            Date d = new Date();
              SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
              String dd = sd.format(d);
              ps.setString(4, dd);
               int x = ps.executeUpdate();
              if(x>0)    
              {
                  JOptionPane.showMessageDialog(null, "APPOINTMENT PROCESSED");
                  Appointment ad = new Appointment();
                  ad.setVisible(true);
                  this.dispose();
              }
        }
        catch(Exception e){
            System.out.println(e);
        }
    }                                        

  
    public static void main(String args[]) {
       
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Appointment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Appointment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Appointment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Appointment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
       

        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Appointment().setVisible(true);
            }
        });
    }

                       
    private javax.swing.JTextField dname;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField name;
    private javax.swing.JTextField page;
                      
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Bill.java
package jan1;

public class Bill extends javax.swing.JFrame {

 
    public Bill() {
        initComponents();
    }

  
    @SuppressWarnings("unchecked")
                             
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        a = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        b = new javax.swing.JTextField();
        c = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        g = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Bill of patient");

        jLabel2.setText("ENTER NUMBER OF DAYS PATIENT WAS ADMITTED");

        jLabel3.setText("ENTER  TOTAL COST OF TESTS");

        jLabel4.setText("ENTER TOTAL FEES OF DOCTOR");

        b.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bActionPerformed(evt);
            }
        });

        jButton1.setText("GENERATE BILL");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

     

                        

    private void bActionPerformed(java.awt.event.ActionEvent evt) {                                  
       
    }                                 

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
int d=Integer.parseInt(a.getText());  
int e=Integer.parseInt(b.getText()); 
int f=Integer.parseInt(c.getText());
int m=d*5000+e+f;
g.setText(m+" ");
// TODO add your handling code here:
    }                                        

    public static void main(String args[]) {
      
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Bill().setVisible(true);
            }
        });
    }

                      
    private javax.swing.JTextField a;
    private javax.swing.JTextField b;
    private javax.swing.JTextField c;
    private javax.swing.JTextField g;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
                    
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Connection.java
package jan1;
import java.sql.DriverManager;
import java.sql.Connection;


public class Connectiondb {
    public static Connection getConnection(){
        Connection con=null;
        try{
            Class.forName ("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost:3306/hms","id","password");
        }
        catch(Exception e){
            System.out.println(e);
        }
        return con;
    }
    
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Doctordashboard.java
package jan1;

public class Doctordashboard extends javax.swing.JFrame {

  /
    public Doctordashboard() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
                             
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("WELCOME DOCTOR");

        jMenu1.setText("File");

        jMenuItem1.setText("viewtest");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Addtest");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("patients");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem4.setText("add patient");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem5.setText("update patient");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuItem6.setText("jMenuItem6");
        jMenu1.add(jMenuItem6);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

                        

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new viewtest().setVisible(true);        :
    }                                          

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Addpatient().setVisible(true);      
    }                                          

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Addtest().setVisible(true);        
    }                                          

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Viewpatient().setVisible(true);        
    }                                          

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Updatepatient().setVisible(true);        
    }                                          

  
    public static void main(String args[]) {
    
       

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Doctordashboard().setVisible(true);
            }
        });
    }

                       
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
                      
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Staffdashboard.java
package jan1;

public class Staffdashboard extends javax.swing.JFrame {

   
    public Staffdashboard() {
        initComponents();
    }

 
    @SuppressWarnings("unchecked")
                             
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("welcome staff");

        jMenu1.setText("File");

        jMenuItem1.setText("Add doctor");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Add staff");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Add patient");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem4.setText("Add test");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem5.setText("appointmemts");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuItem6.setText("view doctor");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem6);

        jMenuItem7.setText("Update doctor");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem7);

        jMenuItem8.setText("BILL");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem8);

        jMenuItem9.setText("VIEW DOCTOR");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem9);

        jMenuItem10.setText("VIEW PATIENT");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem10);

        jMenuItem11.setText("VIEW STAFF");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem11);

        jMenuItem12.setText("UPDATE PATIENT");
        jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem12ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem12);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

  
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Adddoctor().setVisible(true);        
    }                                          

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Addstaff().setVisible(true);

    }                                          

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Addpatient().setVisible(true);       
    }                                          

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Addtest().setVisible(true);        
    }                                          

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Appointment().setVisible(true);       
    }                                          

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Viewdoctor_1().setVisible(true);        
    }                                          

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Updatedoctor().setVisible(true);

    }                                          

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Bill().setVisible(true);       
    }                                          

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {                                           
new Viewdoctor_1().setVisible(true);        
    }                                          

    private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {                                            
new Viewpatient().setVisible(true);       
    }                                           

    private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {                                            
new Viewstaff().setVisible(true);

    }                                           

    private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {                                            
new Updatepatient().setVisible(true);        
    }                                           

   
    public static void main(String args[]) {
    
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Staffdashboard().setVisible(true);
            }
        });
    }
                    
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
                      
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Updatedoctor.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;


public class Updatedoctor extends javax.swing.JFrame {


    public Updatedoctor() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
                             
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        adm = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        name = new javax.swing.JTextField();
        age = new javax.swing.JTextField();
        qualification = new javax.swing.JTextField();
        address = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        phone = new javax.swing.JTextField();
        uname = new javax.swing.JTextField();
        pwd = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("UPDATE DOCTOR");

        jLabel2.setText("USER NAME");

        jButton1.setText("search");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("clear");

        jLabel3.setText("name");

        jLabel4.setText("age");

        jLabel5.setText("qualification");

        jLabel6.setText("address");

        jLabel7.setText("phone");

        jLabel8.setText("uname");

        jLabel9.setText("pwd");

        jButton3.setText("submit");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

                         

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
String userName = adm.getText();
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement
                ("select * from doctor where uname=?");
            ps.setString(1,userName);
            ResultSet rs = ps.executeQuery();
            if(rs.next())
            {
              
                adm.setEditable(false);
               
                name.setText(rs.getString(1));
                age.setText(rs.getString(2));
                qualification.setText(rs.getString(3));
                address.setText(rs.getString(4));
                phone.setText(rs.getString(5));
                adm.setText(rs.getString(6));
                  pwd.setText(rs.getString(7));
             
            }
            else
            {
             
                JOptionPane.showMessageDialog(null, "Invalid User Name !!");
            }
        }catch(Exception e){
            System.out.println(e);
        }
              
        
                              
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     uname.setText(" ") ;       
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       try
             {
               Connection con = Connectiondb.getConnection();
                PreparedStatement ps = con.prepareStatement
                ("update doctor set name = ?, age = ?,qualification = ?,address = ?,phone = ?,pwd = ? where uname=?");
               ps.setString(1, name.getText());
              ps.setString(2, age.getText());
              ps.setString(3, qualification.getText());
                ps.setString(4, address.getText());
               ps.setString(5,phone.getText());
             
            ps.setString(6, uname.getText());
            
            ps.setString(7,pwd.getText());
            int x = ps.executeUpdate();
            if(x>0)
            {
                JOptionPane.showMessageDialog(null, "DOCTOR Details updated");
                Updatestaff as = new Updatestaff();
                as.setVisible(true);
                this.dispose();
            }
        }
        catch(Exception e)
        {
            System.out.println(e);
        } 
    
    }                                        

    public static void main(String args[]) {
  
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Updatedoctor().setVisible(true);
            }
        });
    }

                        
    private javax.swing.JTextField address;
    private javax.swing.JTextField adm;
    private javax.swing.JTextField age;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField name;
    private javax.swing.JTextField phone;
    private javax.swing.JTextField pwd;
    private javax.swing.JTextField qualification;
    private javax.swing.JTextField uname;
                    
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Updatepatient.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;


public class Updatepatient extends javax.swing.JFrame {

   
    public Updatepatient() {
        initComponents();
    }

  
    @SuppressWarnings("unchecked")
                         
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        adm = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        name = new javax.swing.JTextField();
        age = new javax.swing.JTextField();
        disease = new javax.swing.JTextField();
        phone_number = new javax.swing.JTextField();
        guardian = new javax.swing.JTextField();
        uname = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        pwd = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("UPDATE PATIENT");

        jLabel2.setText("USER NAME");

        jLabel3.setText("NAME1");

        adm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                admActionPerformed(evt);
            }
        });

        jButton1.setText("SEARCH");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setText("AGE1");

        jLabel6.setText("DISEASE");

        jLabel7.setText("PHONE_NUMBER");

        jLabel8.setText("GUARDOAN");

        jLabel9.setText("UNAME");

        jLabel10.setText("PWD");

        name.setText("\\\\");

            jButton2.setText("UPDATE");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });

            pwd.setText("jPasswordField1");

                                 

    private void admActionPerformed(java.awt.event.ActionEvent evt) {                                    
        
    }                                   

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
String userName = adm.getText();
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement
                ("select * from patient where uname=?");
            ps.setString(1,userName);
            ResultSet rs = ps.executeQuery();
            if(rs.next())
            {
                
                adm.setEditable(false);
               
                name.setText(rs.getString(1));
                age.setText(rs.getString(2));
                disease.setText(rs.getString(3));
                guardian.setText(rs.getString(4));
                phone_number.setText(rs.getString(5));
                uname.setText(rs.getString(6));
                  pwd.setText(rs.getString(7));
             
            }
            else
            {
                //not exists
                JOptionPane.showMessageDialog(null, "Invalid User Name !!");
            }
        }catch(Exception e){
            System.out.println(e);
        }        // TODO add your handling code here:
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
 try
             {
               Connection con = Connectiondb.getConnection();
                PreparedStatement ps = con.prepareStatement
                ("update patient set name1 = ?, age1 = ?,disease = ?,phone_number = ?,guardian = ?,pwd = ? where uname=?");
               ps.setString(1, name.getText());
              ps.setString(2, age.getText());
              ps.setString(3, disease.getText());
                ps.setString(4, phone_number.getText());
               ps.setString(5,guardian.getText());
             
            ps.setString(6, uname.getText());
            
            ps.setString(7,pwd.getText());
            int x = ps.executeUpdate();
            if(x>0)
            {
                JOptionPane.showMessageDialog(null, "patient Details updated");
                Updatestaff as = new Updatestaff();
                as.setVisible(true);
                this.dispose();
            }
        }
        catch(Exception e)
        {
            System.out.println(e);
        }        
    }                                        

   
    public static void main(String args[]) {
   
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Updatepatient().setVisible(true);
            }
        });
    }

                        
    private javax.swing.JTextField adm;
    private javax.swing.JTextField age;
    private javax.swing.JTextField disease;
    private javax.swing.JTextField guardian;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField name;
    private javax.swing.JTextField phone_number;
    private javax.swing.JPasswordField pwd;
    private javax.swing.JTextField uname;
                     
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Updatestaff.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;

/**
 *
 * @author lenovo
 */
public class Updatestaff extends javax.swing.JFrame {

  
    public Updatestaff() {
        initComponents();
    }

    
    @SuppressWarnings("unchecked")
                            
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        adm = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        name = new javax.swing.JTextField();
        age = new javax.swing.JTextField();
        qualification = new javax.swing.JTextField();
        address = new javax.swing.JTextField();
        phone = new javax.swing.JTextField();
        uname = new javax.swing.JTextField();
        pwd = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("UPDATE STAFF");

        jLabel2.setText("USER NAME");

        jButton1.setText("SEARCH");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("CLEAR");

        jLabel3.setText("NAME");

        jLabel4.setText("AGE");

        jLabel5.setText("QUALIFICATION");

        jLabel6.setText("ADDRESS");

        jLabel7.setText("PHONE");

        jLabel8.setText("UNAME");

        jLabel9.setText("PWD");

        phone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                phoneActionPerformed(evt);
            }
        });

        pwd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pwdActionPerformed(evt);
            }
        });

        jButton3.setText("UPDATE");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

                          

    private void phoneActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
    }                                     

    private void pwdActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
    }                                   

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
 String userName = adm.getText();
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement
                ("select * from staff where uname=?");
            ps.setString(1, userName);
            ResultSet rs = ps.executeQuery();
            if(rs.next())
            {
                //exist
                adm.setEditable(false);
               
                name.setText(rs.getString(1));
                age.setText(rs.getString(2));
                qualification.setText(rs.getString(3));
                address.setText(rs.getString(4));
                phone.setText(rs.getString(5));
                uname.setText(rs.getString(6));
                  pwd.setText(rs.getString(7));
             
            }
            else
            {
                //not exists
                JOptionPane.showMessageDialog(null, "Invalid User Name !!");
            }
        }catch(Exception e){
            System.out.println(e);
        }
              
        
                              
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     try
             {
               Connection con = Connectiondb.getConnection();
                PreparedStatement ps = con.prepareStatement
                ("update staff set name = ?, age = ?,qualification = ?,address = ?,phone = ?,pwd = ? where uname=?");
               ps.setString(1, name.getText());
              ps.setString(2, age.getText());
              ps.setString(3, qualification.getText());
                ps.setString(4, address.getText());
               ps.setString(5,phone.getText());
             
            ps.setString(6, uname.getText());
            
            ps.setString(7,pwd.getText());
            int x = ps.executeUpdate();
            if(x>0)
            {
                JOptionPane.showMessageDialog(null, "Staff Details updated");
                Updatestaff as = new Updatestaff();
                as.setVisible(true);
                this.dispose();
            }
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }                                        

   
    public static void main(String args[]) {
    
   
     
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Updatestaff().setVisible(true);
            }
        });
    }

                       
    private javax.swing.JTextField address;
    private javax.swing.JTextField adm;
    private javax.swing.JTextField age;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField name;
    private javax.swing.JTextField phone;
    private javax.swing.JTextField pwd;
    private javax.swing.JTextField qualification;
    private javax.swing.JTextField uname;
                      
}
-------------------------------------------------------------------------------------------------------------
Viewdoctor_1.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.table.DefaultTableModel;



public class Viewdoctor_1 extends javax.swing.JFrame {

    public Viewdoctor_1() {
        initComponents();
    }

 
    @SuppressWarnings("unchecked")
                             
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "name", "age", "qualification", "address", "phone", "uname", "pwd"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
        });
        jScrollPane1.setViewportView(jTable1);

                           

    private void formWindowActivated(java.awt.event.WindowEvent evt) {                                     
         DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement("select * from doctor");
            ResultSet rs = ps.executeQuery();
            while(rs.next())
            {
                String name = rs.getString(1);
                String  age = rs.getString(2);
                String qualification = rs.getString(3);
                String address = rs.getString(4);
                String phone = rs.getString(5);
                String uname = rs.getString(6);
                String pwd = rs.getString(7);
                Object ob[] = {name, age, qualification, address, phone,uname,pwd};
                model.addRow(ob);
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }                                    

  
    public static void main(String args[]) {
    

        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Viewdoctor_1().setVisible(true);
            }
        });
    }

                        
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
                      
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Viewpatient.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.table.DefaultTableModel;



public class Viewpatient extends javax.swing.JFrame {

    
    public Viewpatient() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "name", "age", "disease", "phone_number", "guardian", "uname", "pwd"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

    
    private void formWindowActivated(java.awt.event.WindowEvent evt) {                                     
         DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement("select * from patient");
            ResultSet rs = ps.executeQuery();
            while(rs.next())
            {
                String name1 = rs.getString(1);
                String  age1 = rs.getString(2);
                String disease = rs.getString(3);
                String phone_number = rs.getString(4);
                String guardian = rs.getString(5);
                String uname = rs.getString(6);
                String pwd = rs.getString(7);
                Object ob[] = {name1, age1, disease, phone_number, guardian,uname,pwd};
                model.addRow(ob);
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }                                    

   
    public static void main(String args[]) {
       
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Viewpatient().setVisible(true);
            }
        });
    }

                        
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
                      
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------Viewstaff.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.table.DefaultTableModel;


public class Viewstaff extends javax.swing.JFrame {

    public Viewstaff() {
        initComponents();
    }


    @SuppressWarnings("unchecked")
                             
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "name", "age", "qualification", "address", "phone", "uname", "pwd"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

    private void formWindowActivated(java.awt.event.WindowEvent evt) {                                     
         DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement("select * from doctor");
            ResultSet rs = ps.executeQuery();
            while(rs.next())
            {
                String name = rs.getString(1);
                String  age = rs.getString(2);
                String qualification = rs.getString(3);
                String address = rs.getString(4);
                String phone = rs.getString(5);
                String uname = rs.getString(6);
                String pwd = rs.getString(7);
                Object ob[] = {name, age, qualification, address, phone,uname,pwd};
                model.addRow(ob);
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }                                    

    public static void main(String args[]) {
      
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Viewstaff().setVisible(true);
            }
        });
    }

                      
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
                  
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
hmsproject.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class hmsproject extends javax.swing.JFrame {

    
    public hmsproject() {
        initComponents();
    }

   
    @SuppressWarnings("unchecked")
                          
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        staffr = new javax.swing.JRadioButton();
        doctorr = new javax.swing.JRadioButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        namer = new javax.swing.JTextField();
        pwd = new javax.swing.JPasswordField();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("LOGIN FORM");

        jLabel2.setText("NAME ");

        jLabel3.setText("PASSWORD");

        buttonGroup1.add(staffr);
        staffr.setText("STAFF");

        buttonGroup1.add(doctorr);
        doctorr.setText("DOCTOR");

        jButton1.setText("LOGIN");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("CLEAR");

        jLabel4.setText("LOGIN AS");

                           

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         
        try{
            Connection con=Connectiondb.getConnection();
            PreparedStatement ps=null;
            if(staffr.isSelected()){
                ps=con.prepareStatement("select * from staff where uname=? and pwd=?");
                ps.setString(1,namer.getText());
                 ps.setString(2,pwd.getText());
                ResultSet rs=ps.executeQuery();
                if(rs.next()){
                      JOptionPane.showMessageDialog(null, "Welcome STAFF");
                    Staffdashboard sd = new Staffdashboard();
                    sd.setVisible(true);        //to open new frame ad
                    this.dispose();
                }
                else
                {
                    //invalid admin
                    JOptionPane.showMessageDialog(null, "Invalid Uname or Password");
                    hmsproject hms = new hmsproject();
                    hms.setVisible(true);        //to open new frame ad
                    this.dispose();             //to close current frame
                }
                    
                
            }
              else if(doctorr.isSelected())      //radio button selection
            {
                //teacher login
                ps = con.prepareStatement
                    ("select * from doctor where uname=? and pwd=?");
                ps.setString(1, namer.getText());
                ps.setString(2, pwd.getText());
                ResultSet rs=ps.executeQuery();
                if(rs.next())
                {   // valid teacher
                    JOptionPane.showMessageDialog(null,"welocome DOCTOR");
                    Doctordashboard td =new Doctordashboard();
                    td.setVisible(true);
                    this.dispose();
                    
                }
                else
                {  // Invalid teacher
                    JOptionPane.showMessageDialog(null,"Invalid username and password");
                    hmsproject hms = new hmsproject();
                    hms.setVisible(true);
                    this.dispose();
                    
                }
                
                
            }
   
        }  catch(Exception e)
        {
            System.out.println(e);
        }
        
 
    }                                        

  
    public static void main(String args[]) {
       
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new hmsproject().setVisible(true);
            }
        });
    }

                       
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JRadioButton doctorr;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField namer;
    private javax.swing.JPasswordField pwd;
    private javax.swing.JRadioButton staffr;
                  
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------Viewtest.java
package jan1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.table.DefaultTableModel;


public class viewtest extends javax.swing.JFrame {

   
    public viewtest() {
        initComponents();
    }

   
    @SuppressWarnings("unchecked")
                             
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "NAME", "FEES", "DESC", "DOCT"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

       
    private void formWindowActivated(java.awt.event.WindowEvent evt) {                                     
          DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
        try{
            Connection con = Connectiondb.getConnection();
            PreparedStatement ps = con.prepareStatement("select * from teacher");
            ResultSet rs = ps.executeQuery();
            while(rs.next())
            {
                String name = rs.getString(1);
                String fees = rs.getString(2);
                String desc= rs.getString(3);
                String doct = rs.getString(4);
            
                
                Object ob[] = {name, fees, desc,doct };
                model.addRow(ob);
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }                                    


    public static void main(String args[]) {
      
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new viewtest().setVisible(true);
            }
        });
    }
                     
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
                      
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
queries for creating tables
create database hms;// for creating database
use hms;
create table staff(
name varchar(100),
age varchar(100),
qualification varchar(100),
address varchar(100),
phone varchar(100),
uname varchar(100),
pwd varchar(100));

create table doctor(
name varchar(100),
age varchar(100),
qualification varchar(100),
address varchar(100),
phone varchar(10),
uname varchar(100),
pwd varchar(100));
  

create table patient(
name1 varchar(100),
age1 varchar(100),
disease varchar(100),
phone_number varchar(100),
guardian varchar(100),
uname varchar(100),
pwd varchar(100));

create table appointment(
name varchar(100),
dname varchar(100),
page varchar(100),
date varchar(100));

create table test(
name1 varchar(100),
fees varchar(100),
desc varchar(100),
doct varchar(100));


 

In the above code, jan1 is the name of the package. We create all the classes under the same package so that we can easily inherit methods of different classes.

so we can say that jan1 is the package and

  1. Adddoctor.java
  2. Addpatient.java
  3. Addstaff.java
  4. Addtest.java
  5. Appointment.java
  6. Bill.java
  7. Connection.java
  8. Doctordashboard.java
  9. Staffdashboard.java
  10. Updatedoctor.java
  11. Updatepatient.java
  12. Updatestaff.java
  13. Viewdoctor_1.java
  14. Viewpatient.java
  15. Viewstaff.java
  16. hmsproject.java
  17. Viewtest.java

are the classes inside package jan1.

For Connectivity

We use Class.forName(“com.mysql.jdbc.Driver”) for loading Mysql driver to establish Connection.

Connection con; con=DriverManager.getConnection(“JDBC:mysql://localhost:3306/hms”,”root”,”98188“);

A connection is an interface that we use for the connection. In the above bold link localhost is the name of the server,hms is the name of the database, the root is the id of Mysql and 98188 is the password of Mysql.

This Connection.java is further inherited by each and every class because every class is either fetching data from the database or entering data in the database. And in each class

PreparedStatement stmt=con.createStatement();

is used. We use the prepareStatement() method of Connection interface to prepare the SQL statements.

We use the object of the Statement interface for executing queries. executeQuery() method is used for executing database queries. And the object of ResultSet is either used to fetch or to store records in the database. These statements discussed below are used for connectivity.

  1. Class.forName (“com.mysql.jdbc.Driver”);
  2. Connection con=null;
  3. con=DriverManager.getConnection(“jdbc:mysql://localhost:3306/hms”,”root”,”98188″);
  4. Statement ps=con.createStatement(” sql query “)
  5. ResultaSet rs=ps.executeQuery(” sql query “)
  6. rs.setString() or rs.getString()

We can enter data to the database using ps.setString.

PrepareStatement is the Interface and prepareStatement() is the name of the method. we can differentiate both on the basis of the first letter of their spelling ie. p. In case of Interface we use capital p (P) but in case of the method we use small p (p).

And we can fetch data from the database using ps.getString.

And At last, we close the connection using con.close().

For generating the connection, libraries and jar files are required.

Before using these Statements described above, package java.sql must be imported.

Front end

Further to make it attractive we use a graphical user interface. For generating front end we can use

  1. label
  2. text area
  3. button
  4. button group
  5. password field
  6. radio buttons

These labels, swings, buttons, etc are part of swings. For using swings, we usually import swing package. Syntax ( import javax.swing.*)

JOptionPane.showMessageDialog(null,”ANY MESSAGE”)  displays dialogue box containing message on the screen.

  1. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)

2. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)

We use these methods to describe the working of the project on clicking the button.

jButton2,jButton3 are the names of the buttons we can change their names if we want.

jButton2ActionPerformed(java.awt.event.ActionEvent evt) is the complete name of method.

We use private access specifier as private specifiers specify that we can run the method only within the same class. Any other class of the same package will not be able to access the methods.

Exceptions

We use the Try-catch block in case of java database connectivity for the normal flow of code ie. flow of code is not affected by any Exception. Generally, code is enclosed in the try block and catch block is used to catch the exception thrown by the try block. We can also use finally block. Finally block is always executed by the compiler.

 

To run the entire hospital management project in Java follow these steps

To run the project First of all run hms.java

The form that we will receive by running hms.java class.

hosiptal managemnet system in Java

we can either log in as a doctor or as staff by entering a valid username and password.

If we log in as doctor we will receive doctor dashboard

hosiptal managemnet system in Java doctor dashboard

If we will log in as staff we will receive staff dashboard

staffdashboard.docx

Further, we can run any file from the dashboard.

some of the forms from the project are:

output.docx

Also read:

Leave a Reply

Your email address will not be published. Required fields are marked *