Student Record Management System in Java | Mini Project

Student Record Management System in Java

English: This Java mini project helps in managing student records using Java and MySQL. It provides features to add, update, delete, search, and display student details with a GUI interface.

हिंदी: यह Java प्रोजेक्ट छात्रों का रिकॉर्ड मैनेज करने के लिए बनाया गया है। इसमें Java और MySQL का उपयोग किया गया है। आप स्टूडेंट को Add, Update, Delete और Search कर सकते हैं।

🔹 Features / विशेषताएं

  • Add new student records / नया छात्र जोड़ें
  • Update existing student / छात्र की जानकारी अपडेट करें
  • Delete student by Roll No / रोल नंबर से हटाएं
  • View all student records / सभी छात्रों को देखें
  • Search by name or roll number / नाम या रोल नंबर से खोजें
  • Swing GUI for easy interaction / GUI इंटरफ़ेस

📦 MySQL Table Structure

CREATE DATABASE student_db;

USE student_db;

CREATE TABLE students (
  roll_no INT PRIMARY KEY,
  name VARCHAR(100),
  course VARCHAR(50),
  marks INT
);

🖥️ Java Code (with Swing GUI + JDBC)

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class StudentRecordGUI extends JFrame {
    Connection conn;

    StudentRecordGUI() {
        setTitle("Student Management System");
        setSize(400, 500);
        setLayout(new GridLayout(6, 2));
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        JLabel l1 = new JLabel("Roll No:");
        JTextField t1 = new JTextField();
        JLabel l2 = new JLabel("Name:");
        JTextField t2 = new JTextField();
        JLabel l3 = new JLabel("Course:");
        JTextField t3 = new JTextField();
        JLabel l4 = new JLabel("Marks:");
        JTextField t4 = new JTextField();

        JButton add = new JButton("Add");
        JButton search = new JButton("Search");

        add(l1); add(t1); add(l2); add(t2);
        add(l3); add(t3); add(l4); add(t4);
        add(add); add(search);

        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student_db", "root", "your_password");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "DB Error: " + e.getMessage());
        }

        add.addActionListener(e -> {
            try {
                String sql = "INSERT INTO students VALUES (?, ?, ?, ?)";
                PreparedStatement ps = conn.prepareStatement(sql);
                ps.setInt(1, Integer.parseInt(t1.getText()));
                ps.setString(2, t2.getText());
                ps.setString(3, t3.getText());
                ps.setInt(4, Integer.parseInt(t4.getText()));
                ps.executeUpdate();
                JOptionPane.showMessageDialog(this, "Student Added!");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage());
            }
        });

        search.addActionListener(e -> {
            try {
                String sql = "SELECT * FROM students WHERE roll_no = ? OR name = ?";
                PreparedStatement ps = conn.prepareStatement(sql);
                ps.setString(1, t1.getText());
                ps.setString(2, t2.getText());
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    t1.setText(rs.getString("roll_no"));
                    t2.setText(rs.getString("name"));
                    t3.setText(rs.getString("course"));
                    t4.setText(rs.getString("marks"));
                } else {
                    JOptionPane.showMessageDialog(this, "Student Not Found!");
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage());
            }
        });

        setVisible(true);
    }

    public static void main(String[] args) {
        new StudentRecordGUI();
    }
}
        

🖨️ Expected Output

✅ Student Added Successfully
✅ Record Found: Roll No: 101, Name: Ramesh, Course: Java, Marks: 85
❌ Student Not Found!