The Online Attendance Management System Java Project creates a system for colleges and institutions to record and update the attendance of students. To build this Java project, we created a framework that takes input from the user for student name, subject, total classes, and classes attended. After entering the details, when the user hits the submit button, all the details will be saved permanently in the database.
Introduction
Our attendance management system offers functionality to input, update, and display student attendance records for various subjects. Built with JDBC (Java Database Connectivity), the system interfaces seamlessly with a MySQL database hosted locally to store and retrieve attendance data. To make the project more interactive for its users, we have used the Swing module to implement the GUI.
Our main interface includes input fields for a student’s name, the total classes held, and the number of classes the student attended. Users can select a subject (like PHYSICS, CHEMISTRY, or MATHS) via a dropdown. There are dedicated buttons to either add new records or update existing ones. Moreover, a table view offers a comprehensive look at all the stored attendance records, and users can click on a table row to quickly populate the input fields for potential updates.
Objectives
Here are the objectives for building the Attendance Management System Java Project:
1. Digital Attendance Tracking: Transition from traditional manual methods of tracking attendance (like registers or sheets) to a digital platform, ensuring data accuracy and ease of access.
2. Data Storage and Retrieval: Implement a system that reliably stores student attendance records in a local MySQL database and displays all the attendance records in a tabulated format, offering users an overview of data and facilitating quick edits by simply clicking on a specific row.
3. User-Friendly Interface: Develop an intuitive GUI using Java’s Swing framework, allowing users to input and view attendance data seamlessly.
4. Versatile Subject Handling: Enable the tracking of student attendance across multiple subjects, such as PHYSICS, CHEMISTRY, and MATHS.
5. Data Validation: Ensure that necessary fields, such as a student’s name and total classes, are filled in before data is stored to prevent incomplete or inaccurate records.
6. Real-Time Attendance Percentage Calculation: Automatically compute the percentage of classes attended by a student based on the input data, assisting in the analysis of attendance trends or determining eligibility criteria that depend on attendance percentages.
Requirements
Development Environment:
- Operating System: With enough processing power and memory to run a Java application and a MySQL server.
- Java Development Kit (JDK): You must have the JDK installed to compile and run Java applications.
- Integrated Development Environment (IDE): An IDE such as IntelliJ IDEA or Eclipse to facilitate coding, debugging, and project management.
Database:
- MySQL Database Server: The system uses a MySQL database to store and retrieve attendance records.
- MySQL JDBC Driver: This is a Java library that enables the application to interact with the MySQL database. In our code, it’s referenced as “com.mysql.cj.jdbc.Driver”.
Java Libraries:
- Java Swing Libraries: Used for building the application’s graphical user interface (GUI).
- Java’s Abstract Window Toolkit (AWT): Supports event-handling functionality, among other things.
Source Code
package com.company; public class Main { public static void main(String[] args) { new Attendance(); } } package com.company; import javax.swing.*; import java.awt.* import java.sql.*; import java.util.*; public class Attendance { private JTextField nameData; private JTextField totalClasses; private JTable table1; private JButton ADDRECORDButton; private JButton UPDATERECORDButton; private JPanel resultPanel; private JComboBox subject; private JTextField attendance; private int totalMarks=0; JFrame attendF = new JFrame(); public Attendance(){ attendF.setContentPane(resultPanel); attendF.pack(); attendF.setLocationRelativeTo(null); attendF.setVisible(true); tableData(); ADDRECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if( nameData.getText().equals("")|| attendance.getText().equals("")){ JOptionPane.showMessageDialog(null,"Please Fill NAME and Total Classes Fields to add Record."); }else{ try { String sql = "insert into attendance"+"(NAME,SUBJECT,TOTAL_CLASSES,CLASSES_ATTENDED,TOTAL_ATTENDANCE)"+"values (?,?,?,?,?)"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); double attend = (Double.parseDouble(attendance.getText())/Double.parseDouble(totalClasses.getText()))*100.0; statement.setString(1,nameData.getText()); statement.setString(2,""+subject.getSelectedItem()); statement.setString(3,totalClasses.getText()); statement.setString(4,attendance.getText()); statement.setString(5,String.format("%.2f",attend)+"%"); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"STUDENT ADDED SUCCESSFULLY"); attendance.setText(""); }catch (Exception ex){ JOptionPane.showMessageDialog(null,ex.getMessage()); } tableData(); } } }); UPDATERECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String sql=""; double attend = (Double.parseDouble(attendance.getText())/Double.parseDouble(totalClasses.getText()))*100.0; String attend1 = String.format("%.2f",attend)+"%"; try{ if(subject.getSelectedIndex()==0){ sql = "UPDATE attendance "+"SET CLASSES_ATTENDED= '"+attendance.getText()+"' ,TOTAL_ATTENDANCE= '"+attend1+"' "+" WHERE NAME= '"+nameData.getText()+"' AND SUBJECT='PHYSICS'"; }else if(subject.getSelectedIndex()==1){ sql = "UPDATE attendance "+"SET CLASSES_ATTENDED= '"+attendance.getText()+"' ,TOTAL_ATTENDANCE= '"+attend1+"' "+" WHERE NAME= '"+nameData.getText()+"' AND SUBJECT='CHEMISTRY'"; }else { sql = "UPDATE attendance "+"SET CLASSES_ATTENDED= '"+attendance.getText()+"' ,TOTAL_ATTENDANCE= '"+attend1+"' "+" WHERE NAME= '"+nameData.getText()+"' AND SUBJECT='MATHS'"; } Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"Attendance Updated successfully"); }catch (Exception e2){ System.out.println(e2); } tableData(); } }); table1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int i=1; DefaultTableModel dm = (DefaultTableModel)table1.getModel(); int rowIndex = table1.getSelectedRow(); nameData.setText(dm.getValueAt(rowIndex,0).toString()); attendance.setText(dm.getValueAt(rowIndex,3).toString()); totalClasses.setText(dm.getValueAt(rowIndex,2).toString()); } }); } public void tableData() { try{ String a= "Select* from attendance"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); Statement resultQuery = connection.createStatement(); ResultSet queryResult = resultQuery.executeQuery(a); table1.setModel(buildTableModel(queryResult)); }catch (Exception ex1){ JOptionPane.showMessageDialog(null,ex1.getMessage()); } } public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException { ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames = new Vector<String>(); int columnCount = metaData.getColumnCount(); for (int column = 1; column <= columnCount; column++) { columnNames.add(metaData.getColumnName(column)); } // data of the table Vector<Vector<Object>> data = new Vector<Vector<Object>>(); while (rs.next()) { Vector<Object> vector = new Vector<Object>(); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { vector.add(rs.getObject(columnIndex)); } data.add(vector); } return new DefaultTableModel(data, columnNames); } }
Explanation of the Code
Classes
1. Main: This is the entry point for the application. When run, it instantiates an Attendance object which brings up the GUI.
2. Attendance: This class handles the GUI and database operations related to attendance management.
Key Components
1. JFrame & Components: The GUI is built using Swing components. It consists of JTextFields to input the student’s name, the total classes held, and the number of classes attended. A JComboBox is used to select the subject (PHYSICS, CHEMISTRY, or MATHS). There’s also a JTable to display attendance records and two buttons for adding and updating records.
2. Database Connection: The code uses the JDBC (Java Database Connectivity) API to connect to a MySQL database. It assumes the database is hosted locally (jdbc:mysql://localhost:3306/intern), and the username and password are both root.
3. Adding Records: When the “ADD RECORD” button is clicked, the program attempts to insert a new record into the attendance table in the database. Before doing so, it calculates the percentage attendance and then adds this, along with other details, to the table.
4. Updating Records: When the “UPDATE RECORD” button is clicked, the program updates the attendance details of a specific student for a given subject in the attendance table. The subject to update is determined by the selected item in the JComboBox.
5. Displaying Records: The JTable is populated by fetching data from the attendance table in the database. The function buildTableModel converts the ResultSet from the SQL query into a table model suitable for displaying in a JTable.
6. Click Event on JTable: When a row in the JTable is clicked, the respective student’s details are fetched and displayed in the JTextFields for further operations (like updating).
Graphical User Interface(GUI)
1. Our GUI consists of 3 textfields, a combo Box, & a Jtable
2. Two buttons, “Add Record” & “Update Record” respectively.
Output
Main Interface
Conclusion
We have successfully built an Online Attendance Management System Java Project to simplify attendance tracking, improve administrative efficiency, and provide educators or institutions with a reliable tool for monitoring student participation.

As a passionate Java developer with over 10 years of experience, I live and breathe Java programming. I have a deep understanding of Java core concepts such as object-oriented programming, multithreading, exception handling, and Java collections. I am proficient in using Java libraries, frameworks, and tools and can write clean, efficient, and maintainable Java code. I can design and implement RESTful APIs, work with databases, and integrate with various third-party services.
0 Comments