Ajp Report Part B
Ajp Report Part B
1.0 Rationale:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public StudentManagementSystem() {
setTitle("Student Management System by Group 5");
setLayout(null);
setSize(1000, 600);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(jtitle);
add(studentName);
add(studentID);
add(studentGrade);
add(dobLabel);
add(genderLabel);
add(contactLabel);
add(emailLabel);
add(jstudentName);
add(jstudentID);
add(jstudentGrade);
add(dobField);
add(maleRadio);
add(femaleRadio);
add(contactField);
add(emailField);
add(addStudent);
add(reset);
add(deleteRecord);
add(searchField);
add(searchButton);
addStudent.addActionListener(this);
reset.addActionListener(this);
deleteRecord.addActionListener(this);
searchButton.addActionListener(this);
connectToDatabase();
loadStudentDataFromDatabase();
}
jstudentName.setText("");
jstudentID.setText("");
jstudentGrade.setText("");
dobField.setText("");
genderGroup.clearSelection();
contactField.setText("");
emailField.setText("");
insertStudentData(name, id, grade, dob, gender, contact, email);
}
}
if (e.getSource() == reset) {
jstudentName.setText("");
jstudentID.setText("");
jstudentGrade.setText("");
dobField.setText("");
genderGroup.clearSelection();
contactField.setText("");
emailField.setText("");
}
if (e.getSource() == deleteRecord) {
String studentIDToDelete = null;
int selectedRow = studentTable.getSelectedRow();
if (selectedRow >= 0) {
studentIDToDelete = tableModel.getValueAt(selectedRow,
1).toString();
tableModel.removeRow(selectedRow);
deleteStudentData(studentIDToDelete);
}
}
if (e.getSource() == searchButton) {
String searchId = searchField.getText();
for (int row = 0; row < tableModel.getRowCount(); row++) {
if (tableModel.getValueAt(row, 1).equals(searchId)) {
studentTable.setRowSelectionInterval(row, row);
studentTable.setSelectionBackground(Color.YELLOW);
studentTable.setSelectionForeground(Color.BLACK);
break;
}
}
}
}
private boolean isValidEmail(String email) {
return email.matches("^[A-Za-z0-9+_.-]+@(.+)$");
}
try {
PreparedStatement preparedStatement =
connection.prepareStatement(insertQuery);
preparedStatement.setString(1, name);
preparedStatement.setString(2, id);
preparedStatement.setString(3, grade);
preparedStatement.setString(4, dob);
preparedStatement.setString(5, gender);
preparedStatement.setString(6, contact);
preparedStatement.setString(7, email);
if (rowsAffected > 0) {
JOptionPane.showMessageDialog(this, "Student data inserted
successfully", "Success", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "Failed to insert student data",
"Error", JOptionPane.ERROR_MESSAGE);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
while (resultSet.next()) {
String name = resultSet.getString(1);
String id = resultSet.getString(2);
String grade = resultSet.getString(3);
String dob = resultSet.getString(4);
String gender = resultSet.getString(5);
String contact = resultSet.getString(6);
String email = resultSet.getString(7);
} catch (SQLException e) {
e.printStackTrace();
}
}
private void deleteStudentData(String studentID) {
String deleteQuery = "DELETE FROM students WHERE student_id = ?";
try {
PreparedStatement preparedStatement =
connection.prepareStatement(deleteQuery);
preparedStatement.setString(1, studentID);
if (rowsAffected > 0) {
JOptionPane.showMessageDialog(this, "Student data deleted
successfully", "Success", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "Failed to delete student
data", "Error", JOptionPane.ERROR_MESSAGE);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
2.Output
5.0 Actual Resources Used (Mention the actual resources used).
S. No. Name of Specifications Qty
Resource/material
1 Software Google Chrome 1
2 Books Advance java 1
Programming
TechKnowledge
Publications
3 Laptop HP 1
• Student access: Students can use the system to check their attendance,
progress, and results, and submit assignments. They can also view
notifications, timetables, and request documents.
• Teacher access: Teachers can easily access and modify student data.
• Administrator access: Administrators can add, change, and delete
courses and subjects. They can also submit, edit, and delete student
attendance.
• Parent access: Parents can have a clear environment to focus on their
children.
8.0 Team Members with Roll No.
**************