Skip to content

Commit 1ff1931

Browse files
authored
Merge pull request #1 from sankarXace/main
Added all files of project
2 parents 5783de2 + 22dcab0 commit 1ff1931

File tree

14 files changed

+405
-2
lines changed

14 files changed

+405
-2
lines changed

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# Student-Management-System-in-Java
2-
Student Management System in Java
1+
# Student Management System in JAVA
2+
This is a simple Student Management System project implemented using Java and MySQL. It allows users to perform CRUD (Create, Read, Update, Delete) operations on student data such as ID, first name, last name, major, phone number, GPA, and date of birth.
3+
4+
# Features
5+
* Add a new student
6+
* View student data
7+
* Update student data
8+
* search for a student
9+
* sort students by major, lastname and firstname.
10+
11+
# Requirements
12+
* Java 8 or higher.
13+
* MySQL Server.
14+
15+
# Installation
16+
1. Clone the repository
17+
```bash
18+
git clone https://github.com/your_username/student-management-system.git
19+
```
20+
2. Create a new MySQL database and import the student_data.sql file to
21+
3. create the required table and sample data.
22+
4. Update the MySQL database connection details in the dbConnect class.
23+
5. Build and run the project using a Java IDE or command-line tool.
24+
6. To import *student_data.sql* into your mysql database.
25+
* **Type**: ```mysql -u username -p database_name < file.sql```
26+
* The **username** refers to your MySQL username.
27+
* **database_name** refers to the database you want to import.
28+
* **file.sql** is your file name. (student_data.sql in our case.)
29+
* If you've assigned a password, type it now and press Enter.
30+
31+
# Usage
32+
* Launch the application
33+
* Select the desired operation from the main menu
34+
* Follow the prompts to enter or update student data
35+
36+
# Database Columns
37+
The database table used in this project has the following columns:
38+
39+
* Student_ID: The unique identifier for each student.
40+
* first_name: The first name of the student.
41+
* last_name: The last name of the student.
42+
* major: The major that the student is studying.
43+
* Phone: The phone number of the student.
44+
* GPA: The grade point average of the student.
45+
* DOB: The date of birth of the student.
46+
47+
# Future Enhancements
48+
* Fee tracking
49+
* Attendance management
50+
51+
52+

Student Management System.iml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library>
12+
<CLASSES>
13+
<root url="jar://C:/mysql-connector-j-8.0.32.jar!/" />
14+
</CLASSES>
15+
<JAVADOC />
16+
<SOURCES />
17+
</library>
18+
</orderEntry>
19+
</component>
20+
</module>
7.26 KB
Binary file not shown.
555 Bytes
Binary file not shown.
1.5 KB
Binary file not shown.
1.4 KB
Binary file not shown.

src/AppGUI.java

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
import javax.swing.*;
2+
3+
import java.awt.event.*;
4+
import java.sql.*;
5+
6+
public class AppGUI extends JFrame implements ActionListener {
7+
private final JLabel studentIdLabel, firstNameLabel, lastNameLabel, majorLabel, phoneLabel, gpaLabel, dobLabel;
8+
private final JTextField studentIdField, firstNameField, lastNameField, majorField, phoneField, gpaField, dobField;
9+
private final JButton addButton, displayButton, sortButton, searchButton, modifyButton;
10+
11+
private Statement stmt;
12+
13+
public AppGUI() {
14+
JFrame frame = new JFrame("Student Database");
15+
JPanel panel = new JPanel();
16+
17+
// Initialize labels
18+
studentIdLabel = new JLabel("Student ID:");
19+
firstNameLabel = new JLabel("First Name:");
20+
lastNameLabel = new JLabel("Last Name:");
21+
majorLabel = new JLabel("Major:");
22+
phoneLabel = new JLabel("Phone:");
23+
gpaLabel = new JLabel("GPA:");
24+
dobLabel = new JLabel("Date of Birth (yyyy-mm-dd):");
25+
26+
// Initialize text fields
27+
studentIdField = new JTextField(10);
28+
firstNameField = new JTextField(10);
29+
lastNameField = new JTextField(10);
30+
majorField = new JTextField(10);
31+
phoneField = new JTextField(10);
32+
gpaField = new JTextField(10);
33+
dobField = new JTextField(10);
34+
35+
// Initialize buttons
36+
addButton = new JButton("Add");
37+
displayButton = new JButton("Display");
38+
sortButton = new JButton("Sort");
39+
searchButton = new JButton("Search");
40+
modifyButton = new JButton("Modify");
41+
42+
// Add action listeners to buttons
43+
addButton.addActionListener(this);
44+
displayButton.addActionListener(this);
45+
sortButton.addActionListener(this);
46+
searchButton.addActionListener(this);
47+
modifyButton.addActionListener(this);
48+
49+
// Add components to panel
50+
panel.add(studentIdLabel);
51+
panel.add(studentIdField);
52+
panel.add(firstNameLabel);
53+
panel.add(firstNameField);
54+
panel.add(lastNameLabel);
55+
panel.add(lastNameField);
56+
panel.add(majorLabel);
57+
panel.add(majorField);
58+
panel.add(phoneLabel);
59+
panel.add(phoneField);
60+
panel.add(gpaLabel);
61+
panel.add(gpaField);
62+
panel.add(dobLabel);
63+
panel.add(dobField);
64+
panel.add(addButton);
65+
panel.add(displayButton);
66+
panel.add(sortButton);
67+
panel.add(searchButton);
68+
panel.add(modifyButton);
69+
70+
// Add panel to frame
71+
frame.add(panel);
72+
frame.pack();
73+
frame.setVisible(true);
74+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
75+
}
76+
77+
78+
@Override
79+
public void actionPerformed(ActionEvent e) {
80+
dbConnect db = new dbConnect();
81+
Connection conn;
82+
try {
83+
conn = db.getConnection();
84+
} catch (SQLException | ClassNotFoundException ex) {
85+
throw new RuntimeException(ex);
86+
}
87+
try {
88+
stmt = conn.createStatement();
89+
} catch (SQLException e1) {
90+
e1.printStackTrace();
91+
}
92+
Table tb = new Table();
93+
if (e.getSource() == addButton) {
94+
// Insert new student into database
95+
String sql = "INSERT INTO sdata VALUES('" + studentIdField.getText() + "', '"
96+
+ firstNameField.getText() + "', '" + lastNameField.getText() + "', '" + majorField.getText()
97+
+ "', '" + phoneField.getText() + "', '" + gpaField.getText() + "', '" + dobField.getText() + "')";
98+
try {
99+
stmt.executeUpdate(sql);
100+
JOptionPane.showMessageDialog(null, "Student added successfully.");
101+
} catch (SQLException ex) {
102+
ex.printStackTrace();
103+
}
104+
} else if (e.getSource() == displayButton) {
105+
// Display all sdata in database
106+
String sql = "SELECT * FROM sdata";
107+
108+
try {
109+
ResultSet rs = stmt.executeQuery(sql);
110+
111+
// Create table to display student data
112+
JTable table = new JTable(tb.buildTableModel(rs));
113+
JOptionPane.showMessageDialog(null, new JScrollPane(table));
114+
} catch (SQLException ex) {
115+
ex.printStackTrace();
116+
}
117+
} else if (e.getSource() == sortButton) {
118+
// Sort sdata by selected column
119+
String[] options = {"First Name", "Last Name", "Major"};
120+
int choice = JOptionPane.showOptionDialog(null, "Sort by:", "Sort", JOptionPane.DEFAULT_OPTION,
121+
JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
122+
123+
String sql = "";
124+
switch (choice) {
125+
case 0 -> sql = "SELECT * FROM sdata ORDER BY first_name";
126+
case 1 -> sql = "SELECT * FROM sdata ORDER BY last_name";
127+
case 2 -> sql = "SELECT * FROM sdata ORDER BY major";
128+
default -> {
129+
}
130+
}
131+
try {
132+
ResultSet rs = stmt.executeQuery(sql);
133+
134+
// Create table to display student data
135+
JTable table = new JTable(tb.buildTableModel(rs));
136+
JOptionPane.showMessageDialog(null, new JScrollPane(table));
137+
} catch (SQLException ex) {
138+
ex.printStackTrace();
139+
}
140+
} else if (e.getSource() == searchButton) {
141+
// Search for student by selected column
142+
String[] options = {"Student ID", "Last Name", "Major"};
143+
int choice = JOptionPane.showOptionDialog(null, "Search by:", "Search", JOptionPane.DEFAULT_OPTION,
144+
JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
145+
146+
String column = "";
147+
switch (choice) {
148+
case 0 -> column = "student_id";
149+
case 1 -> column = "last_name";
150+
case 2 -> column = "major";
151+
default -> {
152+
}
153+
}
154+
155+
String searchTerm = JOptionPane.showInputDialog("Enter search term:");
156+
157+
String sql = "SELECT * FROM sdata WHERE " + column + " LIKE '%" + searchTerm + "%'";
158+
159+
try {
160+
ResultSet rs = stmt.executeQuery(sql);
161+
162+
// Create table to display student data
163+
JTable table = new JTable(tb.buildTableModel(rs));
164+
JOptionPane.showMessageDialog(null, new JScrollPane(table));
165+
} catch (SQLException ex) {
166+
ex.printStackTrace();
167+
}
168+
} else if (e.getSource() == modifyButton) {
169+
// Modify selected student's data
170+
String studentId = JOptionPane.showInputDialog("Enter student ID:");
171+
172+
String sql = "SELECT * FROM sdata WHERE student_id = '" + studentId + "'";
173+
174+
try {
175+
ResultSet rs = stmt.executeQuery(sql);
176+
177+
if (rs.next()) {
178+
String[] options = {"First Name", "Last Name", "Major", "Phone", "GPA", "Date of Birth"};
179+
int choice = JOptionPane.showOptionDialog(null, "Select field to modify:", "Modify",
180+
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
181+
182+
String column = "";
183+
switch (choice) {
184+
case 0 -> column = "first_name";
185+
case 1 -> column = "last_name";
186+
case 2 -> column = "major";
187+
case 3 -> column = "phone";
188+
case 4 -> column = "gpa";
189+
case 5 -> column = "date_of_birth";
190+
default -> {
191+
}
192+
}
193+
String newValue = JOptionPane.showInputDialog("Enter new value:");
194+
195+
sql = "UPDATE sdata SET " + column + " = '" + newValue + "' WHERE student_id = '" + studentId + "'";
196+
197+
stmt.executeUpdate(sql);
198+
JOptionPane.showMessageDialog(null, "Student data updated successfully.");
199+
} else {
200+
JOptionPane.showMessageDialog(null, "Student not found.");
201+
}
202+
} catch (SQLException ex) {
203+
ex.printStackTrace();
204+
}
205+
}
206+
}
207+
208+
}

0 commit comments

Comments
 (0)