I want to search for some specific results in Results table, using an id from a different table to calculate cgpa based on the students id selected from studentInfo table, below is what I tried, the issue is that it just computes for the first Id or rather student
String lev = levelCombo.getSelectedItem().toString();
int leve = Integer.parseInt(lev);
int le = leve / 100;
try {
String sql
= "select idNumber from studentInfo where level ='" + lev + "' ";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while (rs.next()) {
String idNumb = rs.getString("idNumber");
cgpa(idNumb, le);
System.out.print("" + idNumb);
}
} catch (Exception e) {
}
}
public void cgpa(String idnumber, int level) {
float units = 0;
float ugps = 0;
float cgp = 0;
for (int i = 1; i <= level; i++) {
try {
String sql = "select sum(UNIT) ,sum(UGP) ,round(sum(UGP) / NULLIF(sum(UNIT), 0), 2) from Results where ID_NUMBER = ? and level ='" + i + "' ";
pst = conn.prepareStatement(sql);
pst.setString(1, idnumber);
rs = pst.executeQuery();
while (rs.next()) {
Float un = rs.getFloat("sum(UNIT)");
Float gp = rs.getFloat("sum(UGP)");
// Float sum=rs.getFloat("round(sum(UGP)/NULLIF(sum(UNIT), 0),2)");
units += un;
ugps += gp;
cgp = ugps / units;
String sql1 = "update academicstatus set cgpa ='" + cgp + "' ,product='" + ugps
+ "',unit='" + units + "' where idnumber = ? ";
updateAcademicstatus(cgp, ugps, units, idnumber);
pst = conn.prepareStatement(sql1);
pst.setString(1, idnumber);
pst.executeUpdate();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
rs.close();
pst.close();
} catch (Exception e) {
}
}
}
}