Java Student Management System – A smarter way to manage your student records.

This project aims to guide you in creating a Student Management System using Java, Java Swing, and SQLite within the Eclipse IDE. The system will be designed to store and manage student information such as IDs, contact information, E-mail, Father’s Name, and addresses, etc.

Java Student Management System

The main objective of this project is to develop a Student Management System that utilizes Java, Java Swing, and SQLite. The system will allow you to store and retrieve student information such as IDs, contacts, and addresses.

By following this project, you will gain a basic understanding of how to create a GUI using Java Swing, connect to an SQLite database, and implement the functionality for storing and retrieving data.e.

Prerequisites for Student Management System using Java

  • Basic knowledge of Java programming
  • Familiarity with Java Swing for creating GUI applications
  • Knowledge of databases and SQL queries.
  • Understanding of JAR files and how they are used in Java projects.
  • Understanding of database management and SQLite database.
  • Any Java IDE (Eclipse recommended)

It is recommended to use the WindowBuilder plugin in Eclipse to make GUI development easier. The WindowBuilder allows you to drag-and-drop GUI components and generates the code automatically, making it easier to create and design Java graphical user interfaces.

Download Java Student Management System Project

Please download the source code of Java Student Management System project from the following link: Java Student Management System Project Code

Steps to Create Student Management System using Java

Following are the steps for developing the Java Student Management System project:

Step 1: Setting Up the Project and Classes

  1. Open Eclipse and navigate to “File” > “New” > “Java Project”.
  2. Give your project a name, for example, “Student Management System”.
  3. Right-click on the project and select “New” > “Class”.
  4. Give a name to the first class, such as “StudentManagement”.
  5. Repeat steps 3 and 4 to create another class, “Database”.

Step 2: Incorporating SQLite into the Project

  1. Go to the Project Explorer in Eclipse.
  2. Select the project name by right-clicking on it and choose “Properties”.
  3. In the Properties window, navigate to “Java Build Path” and then click the “Libraries” tab.
  4. Hit the “Add External JARs” button, and locate the SQLite JAR file.
  5. Select the JAR file and press “Open”.
  6. Click “OK” to close the Properties window.

With these steps, SQLite has now been integrated into your Eclipse project.
Note: Before proceeding, ensure you have the SQLite JAR file downloaded and stored in a local location. If not, it can be obtained from MavenRepository.

Step 3: Implementing the Database class created in Step:1

Here’s the complete code for the Database class

package com.TechVidvan;
import java.sql.Statement;
import javax.swing.table.DefaultTableModel;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.sqlite.SQLiteDataSource;
public class Database {
//	declaring connection and datasource variables
  static Connection conn;
  static SQLiteDataSource ds;
  
//	initialize method to initialize the database with students table
  public static void dbInit() {
    ds = new SQLiteDataSource();
    
    try {
ds = new SQLiteDataSource();
ds.setUrl("jdbc:sqlite:StudentManagementDB.db");
} catch ( Exception e ) {
e.printStackTrace();
System.exit(0);
}
try {
   conn = ds.getConnection();
  
   Statement stmt = conn.createStatement();
// 	 sql query to add student table
   String query = "CREATE TABLE IF NOT EXISTS students ( "
   				+ "student_id TEXT PRIMARY KEY ,"
   				+ "student_name TEXT,"
   				+ "father_name TEXT,"
   				+ "student_dob TEXT,"
   				+ "student_gender TEXT,"
   				+ "student_contact TEXT,"
   				+ "student_email TEXT,"
   				+ "section TEXT,"
   				+ "student_address TEXT"
   				+ " );"; 	
// 	 executing the query using statement variable
   stmt.executeUpdate(query);
   conn.close();
  
} catch ( SQLException e ) {
e.printStackTrace();
System.exit( 0 );
}
;
}
  
//	function to add the student into the database
  protected static void insertStudent(String id,String name,String fatherName,
                   String dob,String gender,String contact,String section,String email,String address
                  ) throws SQLException {
    String query = "INSERT INTO students(student_id,student_name,father_name,student_dob,student_gender,student_contact,section,student_email,student_address) "
          + "VALUES("
            +"'"+ id +"',"
            +"'"+ name +"',"
            +"'"+ fatherName +"',"
            +"'"+ dob +"',"
            +"'"+ gender +"',"
            +"'"+ contact +"',"
            +"'"+ section +"',"
            +"'"+ email +"',"
            +"'"+ address +"');" ;
    
    conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    stmt.executeUpdate(query);
    conn.close();
  }
//	Fucntion to update the student data using the id
  protected static void updateStudent(String id,String name,String fatherName,String contact,
       String dob,String gender,String email, String section,String address
      ) throws SQLException {
      String query = "UPDATE students "
          + "SET "
          + "student_name = '"+name + "',"
          + "father_name = '"+fatherName + "',"
          + "student_contact = '"+contact+ "',"
          + "student_dob = '"+dob+ "',"
          + "student_gender = '"+gender + "',"
          + "student_email = '"+email + "',"
          + "section = '"+section + "',"
          + "student_address = '"+address + "'"
          
          + "WHERE "
          + "student_id = '"+id+"'";
      System.out.println(query);
      conn = ds.getConnection();
      Statement stmt = conn.createStatement();
      stmt.executeUpdate(query);
      conn.close();
      }
  //	function to delete the student from the database
  protected static void deleteStudent(String id) throws SQLException {
    String query = "DELETE FROM students WHERE student_id = '"+id+"';";
    conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    stmt.executeUpdate(query);
    conn.close();
  
  }
  //	function that searches the student in the database and updates the values using tabel model
  public static void searchStudents(DefaultTableModel model,String searchTerm) throws SQLException {
    model.setRowCount(0);
    String query = "SELECT * FROM students WHERE student_name LIKE '%"+searchTerm +"%';";
    conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    
    while(rs.next()) {
      String id = rs.getString("student_id");
      String name = rs.getString("student_name");
      String fatherName = rs.getString("father_name");
      String dob = rs.getString("student_dob");
      String gender = rs.getString("student_gender");
      String contact = rs.getString("student_contact");
      String section = rs.getString("section");
      String email = rs.getString("student_email");
      String address = rs.getString("student_address");
      
      
      model.addRow(new Object[]{id,name,fatherName,dob,gender,contact,section,email,address});
      
    }
    
    conn.close();
    rs.close();
    
  }
  // function to fetch the data and add it to the model so that the jtable is updated
  public static void fetchAllData(DefaultTableModel model) throws SQLException {
    model.setRowCount(0);
    String query = "SELECT * FROM students ;";
    conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    
    while(rs.next()) {
      String id = rs.getString("student_id");
      String name = rs.getString("student_name");
      String fatherName = rs.getString("father_name");
      String dob = rs.getString("student_dob");
      String gender = rs.getString("student_gender");
      String contact = rs.getString("student_contact");
      String section = rs.getString("section");
      String email = rs.getString("student_email");
      String address = rs.getString("student_address");
      
      
      model.addRow(new Object[]{id,name,fatherName,dob,gender,contact,section,email,address});
      
    }
    
    conn.close();
    rs.close();
    
  }
}
  • The dbInit method creates a new SQLite database and sets its URL. It also creates a table called “students” if it doesn’t exist already. The table has 9 columns, including “student_id” as the primary key, “student_name,” “father_name,” “student_dob,” “student_gender,” “student_contact,” “student_email,” “section,” and “student_address.”
  • The insertStudent method takes 9 parameters, which correspond to the 9 columns of the “students” table, and inserts a new record into the table using an SQL INSERT statement.
  • The updateStudent method updates an existing record in the “students” table using an SQL UPDATE statement. It takes 9 parameters, which correspond to the columns of the “students” table, and updates the record with a matching “student_id.”
  • The deleteStudent method deletes a record from the “students” table using an SQL DELETE statement. It takes 1 parameter, “id,” which corresponds to the “student_id” of the record to be deleted.
  • The searchStudents method is used to search a student in the database based on the given search term and update the values in the table model.
  1. The method takes two arguments, the first one is a DefaultTableModel object named model which represents the table model and the second one is a String object named searchTerm which represents the search term entered by the user.
  2. The method starts by setting the row count of the model to 0 to clear any existing data in the model.
  3. Next, a SQL query is created which selects all the rows from the students table where the student_name column value matches with the given searchTerm. The query uses the LIKE operator with the % wildcard character to match the search term anywhere in the student_name column.
  4. A database connection is established using the ds object and the query is executed using a Statement object and the executeQuery method. The result of the query is stored in a ResultSet object named rs.
  5. The while loop iterates over the rs object and fetches the values of each column in the current row. The values are stored in local variables such as id, name, fatherName, dob, gender, contact, section, email, and address.
  6. The values are then added as a new row to the model using the addRow method and passing an array of objects that represent the values for each column.
  7. Finally, the database connection is closed and the ResultSet object is closed to release the resources.
  • The fetchAllData method is used to fetch all data from the “students” table in the database and update the values in the table model. The method takes a DefaultTableModel object as an argument.
  1. The method starts by setting the row count of the table model to zero. This is done to clear any previous data in the table model.
  2. Next, the method defines a SQL query that selects all data from the “students” table. The method then creates a connection to the database using the ds.getConnection() method. The connection is stored in the conn variable.
  3. A Statement object is then created using the conn connection, and the query is executed using the executeQuery method. The result of the query is stored in a ResultSet object, which is used to loop through the rows of the result set.
  4. For each row in the result set, the method retrieves the values of each column in the row and stores them in local variables. The values are then added to the table model as a new row using the addRow method of the DefaultTableModel object.
  5. Finally, the method closes the connection and the result set and returns.

Step 4: Implementing the StudentManagement class created in Step:1

Here’s the complete code for the StudentManagement class:

package com.TechVidvan;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JTextArea;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class StudentManagement {
  private JFrame frmStduentManagementSystem;
  private JTextField nameTextField;
  private JTextField fatherNameTextField;
  private JTextField contactTextField;
  private JTextField emailTextField;
  private JTextField idTextField;
  private JTextField dobtextField;
  private JTable table;
  private JTextField sectionTextField;
  private JTextField deletetextfield;
  private JTextField searchTextField;
  /**
   * Launch the application.
   */
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        try {
          Database.dbInit();
          StudentManagement window = new StudentManagement();
          window.frmStduentManagementSystem.setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }
  /**
   * Create the application.
   */
  public StudentManagement() {
    initialize();
  }
  /**
   * Initialize the contents of the frame.
   */
  private void initialize() {
//		Creating new frame for the components
    frmStduentManagementSystem = new JFrame();
    frmStduentManagementSystem.setTitle("Stduent Management System by TechVidvan");
    frmStduentManagementSystem.setBounds(100, 100, 1100, 600);
    frmStduentManagementSystem.setResizable(false);
    frmStduentManagementSystem.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmStduentManagementSystem.getContentPane();
//		creating the table model for jtable
    DefaultTableModel model = new DefaultTableModel();
    model.addColumn("Id");
    model.addColumn("Name");
    model.addColumn("Father's Name");
    model.addColumn("D.O.B");
    model.addColumn("Gender");
    model.addColumn("Contact");
    model.addColumn("Section");
    model.addColumn("E-mail");
    model.addColumn("Address");
    
//		Adding the UI components
    JPanel inputPanel = new JPanel();
    inputPanel.setBounds(0, 0, 400, 565);
    inputPanel.setBackground(new Color(153, 204, 255));
    GridLayout gl_inputPanel = new GridLayout(0, 2);
    gl_inputPanel.setVgap(30);
    inputPanel.setLayout(gl_inputPanel);
    
    JLabel idLabel = new JLabel("Student ID");
    inputPanel.add(idLabel);
    
    idTextField = new JTextField();
    idTextField.setHorizontalAlignment(SwingConstants.LEFT);
    inputPanel.add(idTextField);
    
    JLabel namelabel = new JLabel("Student Name");
    inputPanel.add(namelabel);
    
    nameTextField = new JTextField();
    nameTextField.setToolTipText("");
    nameTextField.setHorizontalAlignment(SwingConstants.LEFT);
    inputPanel.add(nameTextField);
    
    JLabel fatherNameLabel = new JLabel("Father's Name");
    inputPanel.add(fatherNameLabel);
    
    fatherNameTextField = new JTextField();
    fatherNameTextField.setHorizontalAlignment(SwingConstants.LEFT);
    inputPanel.add(fatherNameTextField);
    
    JLabel dobLabel = new JLabel("Date of Birth");
    inputPanel.add(dobLabel);
    
    dobtextField = new JTextField();
    dobtextField.setHorizontalAlignment(SwingConstants.LEFT);
    inputPanel.add(dobtextField);
    
    JLabel genderLabel = new JLabel("Gender");
    inputPanel.add(genderLabel);
    
    JComboBox<String> genderComboBox = new JComboBox<String>();
    genderComboBox.setEditable(false);
    genderComboBox.setMaximumRowCount(3);
    genderComboBox.addItem("Male");
    genderComboBox.addItem("Female");
    genderComboBox.addItem("Other");
    frmStduentManagementSystem.getContentPane().setLayout(null);
    inputPanel.add(genderComboBox);
    
    JLabel contactLabel = new JLabel("Contact");
    inputPanel.add(contactLabel);
    
    contactTextField = new JTextField();
    contactTextField.setHorizontalAlignment(SwingConstants.LEFT);
    inputPanel.add(contactTextField);
    
    JLabel emailLabel = new JLabel("E-mail");
    inputPanel.add(emailLabel);
    
    emailTextField = new JTextField();
    emailTextField.setHorizontalAlignment(SwingConstants.LEFT);
    inputPanel.add(emailTextField);
    
    JLabel sectionLabel = new JLabel("Section");
    inputPanel.add(sectionLabel);
    
    sectionTextField = new JTextField();
    sectionTextField.setHorizontalAlignment(SwingConstants.LEFT);
    inputPanel.add(sectionTextField);
    
    JLabel addressLabel = new JLabel("Address");
    inputPanel.add(addressLabel);
    
    JTextArea addressTextArea = new JTextArea();
    inputPanel.add(addressTextArea);
    frmStduentManagementSystem.getContentPane().add(inputPanel);
    
//		Adding the insert button action listener to insert the student on click
    JButton insertButton = new JButton("Insert");
    inputPanel.add(insertButton);
    insertButton.addActionListener(new ActionListener() {
      
      @Override
      public void actionPerformed(ActionEvent e) {
        try {
          Database.insertStudent(idTextField.getText(),
                     nameTextField.getText(),
                     fatherNameTextField.getText(),
                     dobtextField.getText(),
                     genderComboBox.getSelectedItem().toString(),
                     contactTextField.getText(),
                     sectionTextField.getText(),
                     emailTextField.getText(),
                     addressTextArea.getText());
          Database.fetchAllData(model);
          JOptionPane.showMessageDialog(inputPanel,"Student successfully inserted","Inserted", JOptionPane.INFORMATION_MESSAGE);
          
        } catch (Exception e2) {
          JOptionPane.showMessageDialog(inputPanel,"Student ID Already exists","ERROR", JOptionPane.ERROR_MESSAGE);
          e2.printStackTrace();
        }
      }
    });
    
//		Adding the update button action listener to update the student data on click
    JButton updateButton = new JButton("Update");
    inputPanel.add(updateButton);
    updateButton.addActionListener(new ActionListener() {
      
      @Override
      public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        try {
          Database.updateStudent(idTextField.getText(),
               nameTextField.getText(),
               fatherNameTextField.getText(),
               dobtextField.getText(),
               genderComboBox.getSelectedItem().toString(),
               contactTextField.getText(),
               emailTextField.getText(),
               sectionTextField.getText(), addressTextArea.getText());
          Database.fetchAllData(model);
          JOptionPane.showMessageDialog(inputPanel,"Student successfully Updated","Updated", JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception e2) {
          
          e2.printStackTrace();
        }
      }
    });
    
    JPanel outputPanel = new JPanel();
    outputPanel.setBounds(400, 0, 700, 565);
    outputPanel.setBackground(new Color(51, 209, 122));
    frmStduentManagementSystem.getContentPane().add(outputPanel);
    
    table = new JTable(model);
    table.setVisible(true);
    outputPanel.setLayout(null);
    
    
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setBounds(0, 143, 700, 421);
    scrollPane.setViewportBorder(null);
    outputPanel.add(scrollPane);
    
    JButton showAllButton = new JButton("Show All");
    showAllButton.setBounds(12, 106, 117, 25);
    outputPanel.add(showAllButton);
    
//		Adding the delete button action listener to delete the student on click
    JButton deleteButton = new JButton("Delete");
    deleteButton.setBounds(12, 12, 117, 25);
    outputPanel.add(deleteButton);
    deleteButton.addActionListener(new ActionListener() {
      
      @Override
      public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        try {
          Database.deleteStudent(deletetextfield.getText());
          Database.fetchAllData(model);
          JOptionPane.showMessageDialog(outputPanel,"Student successfully deleted","Deleted", JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception e2) {
          // TODO: handle exception
          e2.printStackTrace();
        }
      }
    });
    
    deletetextfield = new JTextField();
    deletetextfield.setBounds(154, 12, 114, 25);
    outputPanel.add(deletetextfield);
    deletetextfield.setColumns(10);
    
//		Adding the search button action listener to search the student on click
    JButton searchButton = new JButton("Search");
    searchButton.setBounds(12, 62, 117, 25);
    outputPanel.add(searchButton);
    searchButton.addActionListener(new ActionListener() {
      
      @Override
      public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
          try {
            Database.searchStudents(model,searchTextField.getText() );
            JOptionPane.showMessageDialog(outputPanel,"NOT Found","ERROR", JOptionPane.ERROR_MESSAGE);
          } catch (Exception e2) {
            // TODO: handle exception
          }
      }
    });
    
    searchTextField = new JTextField();
    searchTextField.setColumns(10);
    searchTextField.setBounds(154, 62, 114, 25);
    outputPanel.add(searchTextField);
    
    JLabel label = new JLabel("<- Enter ID to delete");
    label.setBounds(286, 12, 156, 25);
    outputPanel.add(label);
    
//		Adding the show all button action listener to show all the students on click
    JLabel label_1 = new JLabel("<- Enter Name to Search");
    label_1.setBounds(286, 62, 177, 25);
    outputPanel.add(label_1);
    showAllButton.addActionListener(new ActionListener() {
      
      @Override
      public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        try {
          Database.fetchAllData(model);
        } catch (Exception e2) {
          // TODO: handle exception
          e2.printStackTrace();
        }
      }
    });
    
    
    
  }
}
  • insertButton.addActionListener: This is the action listener for the “Insert” button. It listens for the button click event and performs the following actions:

i. It calls the insertStudent method of the Database class and passes the values entered by the user in the text fields and combo box as arguments.
ii. It calls the fetchAllData method of the Database class to retrieve all the data from the database and update the JTable with the latest data.
iii. It shows a success message dialog to the user if the student is inserted successfully.

  • updateButton.addActionListener: This is the action listener for the “Update” button. It listens for the button click event and performs the following actions:

i. It calls the updateStudent method of the Database class and passes the values entered by the user in the text fields and combo box as arguments.
ii. It calls the fetchAllData method of the Database class to retrieve all the data from the database and update the JTable with the latest data.
iii. It shows a success message dialog to the user if the student is updated successfully.

  • deleteButton.addActionListener: This is the action listener for the “Delete” button. It listens for the button click event and performs the following actions:

i. It calls the deleteStudent method of the Database class and passes the student ID entered by the user as an argument.
ii. It calls the fetchAllData method of the Database class to retrieve all the data from the database and update the JTable with the latest data.
iii. It shows a success message dialog to the user if the student is deleted successfully.

  • searchButton.addActionListener: This is the action listener for the “Search” button. It listens for the button click event and performs the following actions:

i. It calls the searchStudents method of the Database class and passes the model of the JTable and the search string entered by the user as arguments.
ii. It shows an error message dialog to the user if the student is not found in the database.

  • showAllButton.addActionListener: This is the action listener for the “Show All” button. It listens for the button click event and performs the following actions:

i. It calls the fetchAllData method of the Database class to retrieve all the data from the database and update the JTable with the latest data

Java Student Management System Output

student management system output

Summary:

In this project, we learned how to build a Student Management System using Java and SQlite database. We familiarized ourselves with the basics of Java and SQlite, then created a user-friendly interface using Swing components and the grid layout.

We also used SQL queries to perform CRUD operations on the database, including inserting, updating, and retrieving student information. We also added action listeners to various buttons for operations such as insert, update, search, delete, and show all.