VERIFY button:
private void verifyButtonActionPerformed(java.awt.event.ActionEvent evt) {
String rollno = rollnoVar.getText().trim();
if (rollno.isEmpty()) {
JOptionPane.showMessageDialog(this, "Please enter Roll No", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
try (
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root",
"");
PreparedStatement ps = con.prepareStatement("SELECT name, department, semester FROM
student_info WHERE rollno = ?");
){
ps.setString(1, rollno);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
// Retrieve data from ResultSet and display in labels
nameVar.setText(rs.getString("name"));
departmentVar.setText(rs.getString("department"));
semesterVar.setSelectedItem(rs.getString("semester"));
JOptionPane.showMessageDialog(this, "Data fetched successfully!");
} else {
JOptionPane.showMessageDialog(this, "No record found for Roll No: " + rollno, "Info",
JOptionPane.INFORMATION_MESSAGE);
// Clear labels if no data found
nameVar.setText("");
departmentVar.setText("");
semesterVar.setSelectedItem("");
}
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Error: " + e.getMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
ADD button:
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","");
System.out.println(con);
PreparedStatement ps = con.prepareStatement("INSERT INTO student_info(name, rollno,
department, semester) VALUES (?, ? ,?, ?)");
ps.setString(1, nameVar.getText());
ps.setString(2, rollnoVar.getText());
ps.setString(3, departmentVar.getText());
ps.setString(4, selectedSemester);
ps.executeUpdate();
System.out.println("Inserted Successfully!");
JOptionPane.showMessageDialog(this, "Added Successfully!");
}catch(ClassNotFoundException | SQLException e){
System.out.println(e);
}
CALCULATE button:
private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {
Integer.parseInt(sub3.getText()) + Integer.parseInt(sub4.getText()) + Integer.parseInt(sub5.getText())
+ Integer.parseInt(sub6.getText());
int s1 = calculateGradePoint((Integer.parseInt(sub1.getText())));
int s2 = calculateGradePoint((Integer.parseInt(sub2.getText())));
int s3 = calculateGradePoint((Integer.parseInt(sub3.getText())));
int s4 = calculateGradePoint((Integer.parseInt(sub4.getText())));
int s5 = calculateGradePoint((Integer.parseInt(sub5.getText())));
int s6 = calculateGradePoint((Integer.parseInt(sub6.getText())));
double cgpa = (double) (s1+s2+s3+s4+s5+s6) / 6; // First divide by 6, then divide by 10 to get
CGPA
label.setText(String.format("Your CGPA is : %.2f", cgpa)); // Display CGPA with 2 decimal places
}
JAVA PROJECT
CGPA CALCULATOR
Team members:
Rounak Naik
Atharv Pednekar
Elizabeth Joseph
Arnav Cundaikar
Block Diagram: