Free Projects

Employee Leave Management System using Java Mysql

This tutorial will teach how to make the Employee Leave Management System using Java Mysql.this system will help you to manage the employee details and leave details.

This is the Main Form of the Project

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        EmployeeLeave el = new EmployeeLeave();
        el.setVisible(true);
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        leave l = new leave();
        l.setVisible(true);
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   
         leavecal lcal = new leavecal();
        lcal.setVisible(true);
        
        
    }

Employee Registation

Establish the Database Connection

    Connection con;
    PreparedStatement pst;
 
      public void Connection()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/emppayroll","root","");    
            
        } catch (ClassNotFoundException ex) {
           ex.printStackTrace();
        } catch (SQLException ex) {
             ex.printStackTrace();
        }  
    }

AutoID Increment

    public void AutoID()
    {
        Connection();
        try {
            Statement s = con.createStatement();
             ResultSet rs = s.executeQuery("Select MAX(empno) from registation");
             rs.next();
             rs.getString("MAX(empno)");
             
             if(rs.getString("MAX(empno)") == null)
             {
                 txtno.setText("EM001");
                 
             }
             else
             {
                 long id = Long.parseLong(rs.getString("MAX(empno)").substring(2,rs.getString("MAX(empno)").length()));
                 id++;
                 
                 txtno.setText("EM" + String.format("%03d", id));
                 
             }
   
             
        } catch (SQLException ex) {
           ex.printStackTrace();
        }
        
    }

Save Button

     String empno = txtno.getText();
        String empname = txtname.getText();
        String category = txtcategory.getText();
        String salary = txtsalary.getText();
        
        Connection();
        
        try {
            pst = con.prepareStatement("insert into registation(empno,empname,category,salary)values(?,?,?,?)");
            pst.setString(1, empno);
            pst.setString(2, empname);
            pst.setString(3, category);
            pst.setString(4, salary);
            pst.executeUpdate();
            JOptionPane.showMessageDialog(this, "Employee Addedddd!!!!!!!!");
            
            txtname.setText("");
            txtcategory.setText("");
            txtsalary.setText("");
            txtname.requestFocus();
            AutoID();
          
        } catch (SQLException ex) {
           ex.printStackTrace();
        }

Cancel Button

 this.hide();

Leave Information Form

Establish the Database Connection

Connection con;
PreparedStatement pst;
PreparedStatement pst1;


 public void Connection()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/emppayroll","root","");    
            
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace(); 
        } catch (SQLException ex) {
           ex.printStackTrace(); 
        }
        
    }

Ok Button

        String casual = txtcasual.getValue().toString();
        String annual = txtannual.getValue().toString();
        String medical = txtmedical.getValue().toString();
        String year = txtyear.getText();
        
        Connection();
        
        try {
            pst  = con.prepareStatement("select empno from registation");
            ResultSet rs = pst.executeQuery();
            
            String empvalue;
            
            while(rs.next())
            {
                empvalue = rs.getString("empno");
                
                pst1 = con.prepareStatement("insert into leaveinformation(empno,causal,annual,medical,year)values(?,?,?,?,?)");
                pst1.setString(1, empvalue);
                pst1.setString(2, casual);
                pst1.setString(3, annual);
                pst1.setString(4, medical);
                pst1.setString(5, year);
                pst1.executeUpdate();
            }
            
            JOptionPane.showMessageDialog(this, "Leave Infromation Addedddd");
 
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

Cancel Button

   this.hide();

Employee Leave Management

Establish the Database Connection and create relevant variables.

    int casual = 0;
    int annual = 0;
    int medical =0;
    
    Connection con;
   
    PreparedStatement pst;
    PreparedStatement pst1;
    PreparedStatement pst2;
   public void Connection()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/emppayroll","root","");    
            
        } catch (ClassNotFoundException ex) {
           ex.printStackTrace();
        } catch (SQLException ex) {
               ex.printStackTrace();
        } 
        
    }

Load the Employee No JCombo

 public void LoadEmpno()
    {
        
        Connection();     
        try {
            pst = con.prepareStatement("select * from registation");
            ResultSet rs = pst.executeQuery();
            txtno.removeAllItems();
            
            
            while(rs.next())
            {
                txtno.addItem(rs.getString("empno"));
                
            }
     
        } catch (SQLException ex) {
            ex.printStackTrace();
        }    
    }

Leave Load

public void Loadleave()
    {
        Connection();
        String empno = txtno.getSelectedItem().toString();
        try {
            pst = con.prepareStatement("select * from leaveinformation where empno = ?");
            pst.setString(1, empno);
            ResultSet rs2 = pst.executeQuery();
            
            if(rs2.next() == false)
            {
                JOptionPane.showMessageDialog(this, "Leave Information Error");
                
            }
            else
            {
                casual = rs2.getInt("causal");
                annual = rs2.getInt("annual");
                medical = rs2.getInt("medical"); 
            }
            
            
        } catch (SQLException ex) {
           ex.printStackTrace();
        } 
    }

if you select the employee no relevant employee details should displayed the below textfields.

  String empno = txtno.getSelectedItem().toString();
        
        Connection();
        
        try {
            pst = con.prepareStatement("select * from registation where empno = ?");
            pst.setString(1, empno);
            ResultSet rs1 = pst.executeQuery();
            
            if(rs1.next() == false)
            {
                JOptionPane.showMessageDialog(this, "Emp no Error");
            }
            else
            {
                String name = rs1.getString("empname");
                txtname.setText(name.trim());
                String category = rs1.getString("category"); 
                txtcategory.setText(category.trim());
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

Ok Button

  Loadleave();
        int bleave = 0;
        
        String empno = txtno.getSelectedItem().toString();
        
        int days = Integer.parseInt(txtdays.getValue().toString());
        
        
        if(rcasual.isSelected() == true)
        {           
          bleave = casual - days; 
          if(bleave < 0)
          {
              JOptionPane.showMessageDialog(this, "You Have a Casual Leave :  " + casual);
    
          }
          else
          {
              try {
                  pst = con.prepareStatement("update leaveinformation set causal = ? where empno = ?");
                    pst.setInt(1, bleave);
                    pst.setString(2, empno);
                    pst.executeUpdate();
                    JOptionPane.showMessageDialog(this, "Your Casual Leave Updated");
                    
                    
              } catch (SQLException ex) {
                  Logger.getLogger(leavecal.class.getName()).log(Level.SEVERE, null, ex);
              }
 
          }         
        }
        
        else if(rannual.isSelected() == true)
        {
            
          bleave = annual - days; 
          if(bleave < 0)
          {
              JOptionPane.showMessageDialog(this, "You Have a Casual Leave :  " + annual);
    
          }
          else
          {
              try {
                   pst1 = con.prepareStatement("update leaveinformation set annual = ? where empno = ?");
                    pst1.setInt(1, bleave);
                    pst1.setString(2, empno);
                    pst1.executeUpdate();
                    JOptionPane.showMessageDialog(this, "Your Annual Leave Updated");
                    
                    
              } catch (SQLException ex) {
                  Logger.getLogger(leavecal.class.getName()).log(Level.SEVERE, null, ex);
              }
 
          }     
        }
      else if(rmedical.isSelected() == true)
        {
            
          bleave = medical - days; 
          if(bleave < 0)
          {
              JOptionPane.showMessageDialog(this, "You Have a Medical Leave :  " + medical);
    
          }
          else
          {
              try {
                   pst1 = con.prepareStatement("update leaveinformation set medical = ? where empno = ?");
                    pst1.setInt(1, bleave);
                    pst1.setString(2, empno);
                    pst1.executeUpdate();
                    JOptionPane.showMessageDialog(this, "Your Medical Leave Updated");
                    
                    
              } catch (SQLException ex) {
                  Logger.getLogger(leavecal.class.getName()).log(Level.SEVERE, null, ex);
              }
 
          }     
        }
        else
      {
          
          JOptionPane.showMessageDialog(this, "Something Wrong");
      }

Cancel Button

this.hide();

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Laravel 11 CRUD Mastering RESTful API MVC with Repository Pattern

In this tutorial will teach Laravel 11 Api MVC with Repository Pattern Crud Application step…

4 weeks ago

Laravel 11 CRUD Application

In this tutorial will teach Laravel 11 CRUD Application step by step. Laravel  11 CRUD…

2 months ago

How to make Times Table in React

in this tutorials we will be talk about how to make a times table in…

2 months ago

Laravel Tutorial: How to Add Numbers Easily Laravel 10

In this tutorials will teach How to add two numbers in Laravel 10. (more…)

2 months ago

Build Full-Stack Node.js MongoDB CRUD App with JWT Authentication

In this tutorial, we will teach the process of building a full-stack application using Node.js,…

3 months ago

Hospital Management System using OOP Java and MySQL

In this tutorial, we will explin you through the process of building a Hospital Management…

4 months ago