0% found this document useful (0 votes)
37 views

Enhanced Student Management System JDBC API Documentation

Uploaded by

a02861805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Enhanced Student Management System JDBC API Documentation

Uploaded by

a02861805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

MICRO PROJECT

OF
ADVANCED JAVA PROGRAMMING (22517)

Submitted for partial fulfillment of the requirement for Diploma in Computer

Science

2024-2025

Topic:
Student Management System Using JDBC API

Submitted by:-
1. Akshat Tiwari (56)
2. Tanishq Bhedarkar (35)
3. Abhay Chouhan (11)
4. Subhan Rathod (27)

HOD Name:-
Mrs.P.S Alur

Under the guidance of


Mrs.P.Kshirsagar

Department of Computer Science Priyadarshini Polytechnic, Nagpur


Table of Contents

1. Introduction
2. Components Used
3. Java Code
4. Java Code Executions
5. Graphical User Interface (GUI) Design
6. JDBC Database Connectivity
7. Database Setup
8. Conclusion
Introduction:
The Student Management System Using JDBC API is a Java-based desktop application
designed to facilitate managing student records in an educational institution. Built with
Java Swing for the GUI and JDBC for database interaction, it allows users to store and
manage details like Name, Aadhar, Contact, Address, Course, Remarks, and an optional
Image for each student.

The document provides in-depth explanations, guiding users through code structure,
database setup, user interface design, and the implementation of each feature.

Components Used:

1. Java Swing Components


Swing is a popular GUI toolkit in Java used for creating desktop applications. The
components from Swing allow for building user-friendly interfaces.

• JFrame: The main window that holds all other components. It serves as the base
container for the application.

• JPanel: A panel to group UI components and manage layout. Panels can contain
components like text fields, labels, and buttons.

• JLabel: A display element for showing static text or images. Used here to label
fields and display images.

• JTextField: A single-line text input field for users to enter data. Used for name,
contact, Aadhar, address, and course inputs.

• JTextArea: A multi-line text input field, often used for remarks or longer
descriptions.

• JButton: A clickable button that triggers actions (e.g., "Submit," "Delete,"


"Edit").

• JTable: A table component for displaying rows and columns of data. It's ideal for
showing the list of students and their attributes.

• JScrollPane: A scrollable container for holding large components, such as JTable


or JTextArea, allowing easy navigation when content exceeds visible area.
2. Event Handling
Java’s event-handling model responds to user actions, like clicking a button or selecting a
row in a table. Key classes used include:

• ActionListener: An interface for handling action events, mainly for button clicks.
Each button in the GUI implements an ActionListener to define what happens
upon clicking.

• EventQueue: A queue that manages events and ensures GUI updates happen on
the Event Dispatch Thread, ensuring responsive GUI updates.

3. Database Connection Components (JDBC)


JDBC (Java Database Connectivity) allows Java applications to interact with databases,
enabling the program to store and retrieve data.

• Connection: Represents the database connection session. Once connected,


operations can be performed on the database.

• DriverManager: A factory class that manages database drivers. It helps establish


a connection using DriverManager.getConnection().

• PreparedStatement: A SQL statement that allows dynamic parameter binding,


improving security against SQL injection.

• ResultSet: A table of data representing the result of a query. It helps retrieve data
from SQL queries and iterate over each row.

4. File Handling
File handling is essential for uploading and displaying images associated with students in
this project.

• File: A class that represents a file in the file system. Used here to choose and set
the image path for student images.

• JFileChooser: A GUI component that presents a dialog for choosing files,


allowing users to select images to upload.
5. Table Model
Used for managing data in JTable, providing flexibility to add, update, or remove rows as
data changes.

• DefaultTableModel: A table model that extends AbstractTableModel, making it


easier to handle data in the table. It stores the rows representing each student and
refreshes based on data changes.

6. Dialogs
Dialogs provide pop-up messages or user confirmations.

• JOptionPane: A utility class to display simple pop-ups for alerts, confirmations,


or information. For example, it’s used to confirm deletions or show errors.

Java Code:
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.sql.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;

public class StudentManagementApp extends JFrame {


private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField txtName, txtAadhar, txtContact, txtAddress, txtCourse;
private JTextArea txtRemark;
private JLabel lblImage;
private String imagePath = ""; // Holds the selected image path
private JTable table;
private DefaultTableModel tableModel;

// JDBC credentials
private static final String DB_URL =
"jdbc:mysql://localhost:3306/student_management";
private static final String USER = "root";
private static final String PASSWORD = "Akshat";
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
try {
StudentManagementApp frame = new StudentManagementApp();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}

public StudentManagementApp() {
setTitle("Student Management System");
setExtendedState(JFrame.MAXIMIZED_BOTH); // Full-screen mode
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = new JPanel();
contentPane.setLayout(null); // Using null layout for absolute positioning
setContentPane(contentPane);

initializeComponents();
loadStudentData(); // Load student data on startup
}

private void initializeComponents() {


// Student Name Field
JLabel lblName = new JLabel("Name:");
lblName.setBounds(30, 30, 120, 25);
contentPane.add(lblName);

txtName = new JTextField();


txtName.setBounds(150, 30, 200, 25);
contentPane.add(txtName);

// Aadhar Field
JLabel lblAadhar = new JLabel("Aadhar:");
lblAadhar.setBounds(30, 70, 120, 25);
contentPane.add(lblAadhar);

txtAadhar = new JTextField();


txtAadhar.setBounds(150, 70, 200, 25);
contentPane.add(txtAadhar);

// Contact Field
JLabel lblContact = new JLabel("Contact:");
lblContact.setBounds(30, 110, 120, 25);
contentPane.add(lblContact);

txtContact = new JTextField();


txtContact.setBounds(150, 110, 200, 25);
contentPane.add(txtContact);

// Address Field
JLabel lblAddress = new JLabel("Address:");
lblAddress.setBounds(30, 150, 120, 25);
contentPane.add(lblAddress);

txtAddress = new JTextField();


txtAddress.setBounds(150, 150, 200, 25);
contentPane.add(txtAddress);

// Course Field
JLabel lblCourse = new JLabel("Course:");
lblCourse.setBounds(30, 190, 120, 25);
contentPane.add(lblCourse);

txtCourse = new JTextField();


txtCourse.setBounds(150, 190, 200, 25);
contentPane.add(txtCourse);

// Remarks Field
JLabel lblRemark = new JLabel("Remarks:");
lblRemark.setBounds(30, 230, 120, 25);
contentPane.add(lblRemark);

txtRemark = new JTextArea();


txtRemark.setBounds(150, 230, 200, 75);
contentPane.add(txtRemark);

// Image Upload
lblImage = new JLabel("No Image Selected");
lblImage.setBounds(150, 320, 200, 100);
lblImage.setBorder(BorderFactory.createLineBorder(Color.BLACK));
contentPane.add(lblImage);

JButton btnUpload = new JButton("Upload Image");


btnUpload.setBounds(150, 420, 200, 30);
btnUpload.addActionListener(e -> uploadImage());
contentPane.add(btnUpload);

// Buttons for submission, editing, viewing, and deleting


JButton btnSubmit = new JButton("Submit");
btnSubmit.setBounds(30, 480, 100, 30);
btnSubmit.addActionListener(e -> submitStudent());
contentPane.add(btnSubmit);

JButton btnEdit = new JButton("Edit");


btnEdit.setBounds(150, 480, 100, 30);
btnEdit.addActionListener(e -> editStudent());
contentPane.add(btnEdit);

JButton btnView = new JButton("View All");


btnView.setBounds(270, 480, 100, 30);
btnView.addActionListener(e -> viewStudents());
contentPane.add(btnView);

JButton btnDelete = new JButton("Delete");


btnDelete.setBounds(390, 480, 100, 30);
btnDelete.addActionListener(e -> deleteStudent());
contentPane.add(btnDelete);

// JTable for displaying students


tableModel = new DefaultTableModel(new String[]{"ID", "Name", "Aadhar",
"Contact", "Address", "Course", "Remarks", "Image"}, 0) {
@Override
public boolean isCellEditable(int row, int column) {
return false; // Make the table non-editable directly
}
};
table = new JTable(tableModel);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(500, 30, 800, 600);
contentPane.add(scrollPane);
}

private void uploadImage() {


JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new FileNameExtensionFilter("Images", "jpg", "jpeg",
"png"));
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
imagePath = file.getAbsolutePath();
lblImage.setText(file.getName());
}
}

private void submitStudent() {


String name = txtName.getText();
String aadhar = txtAadhar.getText();
String contact = txtContact.getText();
String address = txtAddress.getText();
String course = txtCourse.getText();
String remark = txtRemark.getText();

if (name.isEmpty() || aadhar.isEmpty() || contact.isEmpty() || address.isEmpty() ||


course.isEmpty()) {
JOptionPane.showMessageDialog(this, "Please provide all required
information.");
return;
}

try (Connection conn = DriverManager.getConnection(DB_URL, USER,


PASSWORD);
PreparedStatement stmt = conn.prepareStatement("INSERT INTO students
(name, aadhar, contact, address, course, remarks, image) VALUES (?, ?, ?, ?, ?, ?, ?)")) {
stmt.setString(1, name);
stmt.setString(2, aadhar);
stmt.setString(3, contact);
stmt.setString(4, address);
stmt.setString(5, course);
stmt.setString(6, remark);
stmt.setString(7, imagePath);
stmt.executeUpdate();
JOptionPane.showMessageDialog(this, "Submitted Successfully");
loadStudentData(); // Refresh the table
clearInputFields(); // Clear input fields after submission
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Error: " + e.getMessage());
}
}

private void editStudent() {


JOptionPane.showMessageDialog(this, "Edit functionality not yet implemented.");
}

private void viewStudents() {


loadStudentData(); // Refresh the table to show current records
}

private void deleteStudent() {


int selectedRow = table.getSelectedRow();
if (selectedRow == -1) {
JOptionPane.showMessageDialog(this, "Please select a student to delete.");
return;
}

int confirm = JOptionPane.showConfirmDialog(this, "Are you sure you want to


delete this student?", "Confirm Delete", JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
int studentId = (int) tableModel.getValueAt(selectedRow, 0); // Retrieve ID from
table
try (Connection conn = DriverManager.getConnection(DB_URL, USER,
PASSWORD);
PreparedStatement stmt = conn.prepareStatement("DELETE FROM students
WHERE id = ?")) {
stmt.setInt(1, studentId);
stmt.executeUpdate();
JOptionPane.showMessageDialog(this, "Student deleted successfully.");
loadStudentData(); // Refresh the table
clearInputFields(); // Clear input fields after deletion
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Error: " + e.getMessage());
}
}
}

private void loadStudentData() {


tableModel.setRowCount(0); // Clear existing rows
int idCounter = 1; // Start ID sequence from 1
try (Connection conn = DriverManager.getConnection(DB_URL, USER,
PASSWORD);
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM students");
ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
Object[] row = {
idCounter++,
rs.getString("name"),
rs.getString("aadhar"),
rs.getString("contact"),
rs.getString("address"),
rs.getString("course"),
rs.getString("remarks"),
rs.getString("image")
};
tableModel.addRow(row);
}
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Error: " + e.getMessage());
}
}

private void clearInputFields() {


txtName.setText("");
txtAadhar.setText("");
txtContact.setText("");
txtAddress.setText("");
txtCourse.setText("");
txtRemark.setText("");
lblImage.setText("No Image Selected");
imagePath = "";
}
}

Java Code Executions:

1. Main Screen

The main screen of the Student Management System serves as the primary user interface,
displaying fields for student information input (like Name, Aadhar, Contact, Address,
Course, Remarks, and Image upload). It includes buttons for Submit, Edit, View All, and
Delete operations, which interact with the database to manage student records. A JTable
on this screen shows the list of students, and JOptionPane dialogs provide confirmation
messages and alerts
2. Data input screen

The Data Input Screen of the Student Management System serves as the primary
interface for entering and managing student information. This screen provides input fields
for capturing essential details such as Name, Aadhar, Contact, Address, Course,
Remarks, and an option to upload an Image.

Below the input fields are action buttons: Submit, Edit, View All, and Delete. These
buttons allow users to add new records, update existing ones, view all student entries, and
delete records as needed.

A JTable on the right side of the screen displays the student records, showing all
information in a structured format, which enables easy data management and quick
reference. JOptionPane dialogs are utilized to confirm actions and notify users, making
the system interactive and user-friendly.
3. File chooser screen

The File Chooser Screen in the Student Management System allows the user to select
an image file to associate with a student's profile.

In this screen:

• The File Chooser Dialog is open, showing folders and files from the user’s
system. It restricts the file type to display only image formats, such as .jpg, .jpeg,
and .png.

• The user can navigate through directories and choose an image, which will then
be linked to the student's record and displayed in the application.

• The Open button allows the user to confirm their file selection, while the Cancel
button closes the dialog without making any changes.

This screen enables users to easily select and upload images, improving the visual detail
and completeness of each student's profile in the system.
4. Submitted Data Screen

The Submitted Data Screen in the Student Management System shows the details of a student
that has been successfully added to the database.

In this screen:

• The left panel displays blank input fields for Name, Aadhar, Contact, Address, Course,
Remarks, and Image. These fields have been automatically cleared after submission,
ready for the next entry.

• The JTable on the right side lists the submitted student record with columns for ID,
Name, Aadhar, Contact, Address, Course, Remarks, and Image.

• The student record appears with a unique ID assigned, along with the details entered
during submission.

• The Image column displays the path of the uploaded image file associated with the
student.

This screen provides a clear view of the submitted data, enabling users to verify, edit, or delete
records as needed. The layout is designed for easy tracking of multiple student entries within the
system.
5. Data Deleting Screen

The Data Deleting Screen in the Student Management System allows users to remove a
student's record.

• Left Panel: Displays fields (Name, Aadhar, Contact, Address, Course, Remarks,
Image) for reviewing the selected student's details.

• Right Panel: Contains a JTable of all student records; users can select a student
by clicking a row.
• Delete Process: Clicking Delete prompts a confirmation dialog ("Are you sure
you want to delete this record?"). If confirmed, the record is removed from both
the display and the database, and the JTable refreshes.

This design emphasizes user confirmation, enhancing usability and data integrity.

6. MySQL Database Screen

Graphical User Interface (GUI) Design:


The GUI is built using Java Swing components, with an absolute layout for specific
control positioning. Each input field is labeled and arranged in a user-friendly manner.
The interface includes a JTable to display student records, input fields for various
attributes, and buttons for submission, deletion, and editing.
JDBC Database Connectivity:
JDBC provides a means to connect Java applications to a database. In this project, JDBC
is used to perform CRUD (Create, Read, Update, Delete) operations. Below are key steps
for setting up JDBC connectivity:

-Load Driver: Uses `Class.forName` to load the MySQL driver.


-Connection: Establishes a connection using `DriverManager.getConnection`.
-SQL Commands: Prepared SQL commands help ensure data security.
-Close Connection: Each operation closes the connection to free up resources.

Database Setup
The system uses a MySQL database named `student_management` to store student
details. Below is the SQL script to set up the database and table structure:

CREATE DATABASE student_management;


USE student_management;
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
aadhar VARCHAR(12) NOT NULL,
contact VARCHAR(10) NOT NULL,
address VARCHAR(100),
course VARCHAR(50),
remarks TEXT,
image VARCHAR(100)
);

Each column stores specific student details, with `id` set as an auto-incrementing primary
key to ensure unique identification.

Conclusion
This Student Management System is an example of integrating Java and MySQL using
JDBC. By understanding how each component works, developers can expand on this
structure to create more complex systems or add additional features.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy