Free Projects

Employee Allowance Payroll using Java Mysql

This tutorial will teach how to make the Employee Allowance Payroll System step by step in java and mysql.this system will help you to manage the employee details and salary details.

First we have to design the Employee Registation form

after that we have to set the AutoIncrement ID. when the new employee join to the company.so we have to set the auto id generator. i created the AutoID() function and inside the function i wrote the code.

    public void AutoID()
    {
        try {
           connection();
            Statement s = con.createStatement();
            ResultSet rs = s.executeQuery("select MAX(empno) from employee");
            rs.next();
            rs.getString("MAX(empno)");
            
            if( rs.getString("MAX(empno)") == null)
            {
                txtno.setText("ES001");
            }
            else
            {
                long id = Long.parseLong(rs.getString("MAX(empno)").substring(2,rs.getString("MAX(empno)").length()));
                id++;
                txtno.setText("ES" + String.format("%03d" , id));
                
            }
            
            
            
        } catch (SQLException ex) {
            Logger.getLogger(employeereg.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

after that you have call the AutoID() function inside the Constructor of class.

    public employeereg() 
   {
        initComponents();
        AutoID();
    }

Database Connection

Connection con;
PreparedStatement pst;
   
public void connection()
{
        try {
            Class.forName("com.mysql.jdbc.Driver");
             con = DriverManager.getConnection("jdbc:mysql://localhost/empallowance", "root","");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(employeereg.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(employeereg.class.getName()).log(Level.SEVERE, null, ex);
        }
           
}

Save button

   String empno = txtno.getText();
   String empfname = txtfname.getText();
   String emplname = txtlname.getText();
   String address = txtaddress.getText();
   String telno = txttelno.getText();
   String salary = txtsalary.getText();
   String depart = txtdepart.getText();
   connection();
        
        try {
            pst = con.prepareStatement("insert into employee(empno,fname,lname,address,telno,salary,department)values(?,?,?,?,?,?,?)");
            pst.setString(1, empno);
            pst.setString(2, empfname);
            pst.setString(3, emplname);
            pst.setString(4, address);
            pst.setString(5, telno);
            pst.setString(6, salary);
            pst.setString(7, depart);
            pst.executeUpdate();
            JOptionPane.showMessageDialog(this, "Employeee Insertedddd!!!!!!!!");
            AutoID();
            txtfname.setText("");
            txtlname.setText("");
            txtaddress.setText("");
            txttelno.setText("");
            txtsalary.setText("");
            txtdepart.setText("");
            txtfname.requestFocus();
            
            
            
        } catch (SQLException ex) {
            Logger.getLogger(employeereg.class.getName()).log(Level.SEVERE, null, ex);
        }

Allowance Form

Allowance Consists of 3 parts.

  1. Give the allowance to all the employees who work at the company.
  2. Give the allowance to Individual wise.
  3. Give the allowance to Department wise.

Give the allowance to all the employees who work at the company.

Add Button

 String allo = txtallo.getSelectedItem().toString();
 String amount = txtamount.getText();

        connection();
        try {
           pst = con.prepareStatement("select empno from employee");
            ResultSet rs = pst.executeQuery();
            
            String empnovalue;
            while(rs.next())
            {
                
               empnovalue = rs.getString("empno");
               
               pst = con.prepareStatement("insert into allowance(allowance_type,amount,empno)values(?,?,?)");
               pst.setString(1, allo);
                pst.setString(2, amount);
                pst.setString(3, empnovalue);
                pst.executeUpdate();    
            }

          JOptionPane.showMessageDialog(this,"Allowance Added all Employees");
            table_data();            
            
            
        } catch (SQLException ex) {
            Logger.getLogger(allowance.class.getName()).log(Level.SEVERE, null, ex);
        }

Give the allowance to Individual wise

Add Button

  String empno = txtempno.getSelectedItem().toString();
        String allotype = txtinallo.getSelectedItem().toString();
        String amount = txtinamount.getText();
        
        connection();
        
        try {
            pst = con.prepareStatement("insert into allowance(allowance_type,amount,empno)values(?,?,?)");
            pst.setString(1, allotype);
            pst.setString(2, amount);
             pst.setString(3, empno);
             pst.executeUpdate();
             JOptionPane.showMessageDialog(this, "Allowance Addedddd");
             table_data();
             
            
        } catch (SQLException ex) {
            Logger.getLogger(allowance.class.getName()).log(Level.SEVERE, null, ex);
        }

Give the allowance to Department wise

Add Button

String depart = txtdetype.getSelectedItem().toString();
String allo = txtdeallo.getSelectedItem().toString();
String amount = txtdeamount.getText();
connection();
        
        try {
           pst = con.prepareStatement("select empno from employee where department = ?");
           pst.setString(1, depart);
            ResultSet rs = pst.executeQuery();
            
            String empnovalue;
            while(rs.next())
            {
                
               empnovalue = rs.getString("empno");
               
               pst = con.prepareStatement("insert into allowance(allowance_type,amount,empno)values(?,?,?)");
               pst.setString(1, allo);
                pst.setString(2, amount);
                pst.setString(3, empnovalue);
                pst.executeUpdate();
                
                
            }
            
          JOptionPane.showMessageDialog(this,"Allowance Added For Department  Employees");
            table_data();
            
            
            
        } catch (SQLException ex) {
            Logger.getLogger(allowance.class.getName()).log(Level.SEVERE, null, ex);
        }

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

 

admin

Recent Posts

Build Simple Water System Calculator in Java Using Swing

If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…

1 week ago

GitHub Copilot vs Microsoft Copilot Best AI Tool to Use in 2025

GitHub is a powerful tool used by teams and developers around the globe. This guide is…

2 weeks ago

Chat with Claude AI Free – Your Super-Smart AI Buddy

It's like having a super-smart buddy that is always there to help you write stories,…

3 weeks ago

Best Festivals UK 2025 [Free Guide Included]

The UK is known for its rich history, diverse culture, and most of all  its…

3 weeks ago

Bank Holidays 2025 UK – Plan Your Perfect Long Weekends

Do you have a plan for your next holiday? Being aware of the Bank Holidays within the…

3 weeks ago

Master Cursor AI Full Guide for Students & Creators

The world is rapidly changing of software development AI-assisted tools for coding have become the main focus. As…

3 weeks ago