我想在jtextfield中键入studentid后单击jbutton时在jframe上显示一些students。
学生数据存储在mysql数据库中,studentrolls表包含了以bullId为主键、studentid、bachid为外键的学生信息,fees表包含了以bullId为主键、bachid为外键的过去几年和实际年份的所有学生费用记录。
如果选择了jcheckboxonlythiswearfee,我想在jtextfield上插入studentid并单击jbutton only actual year fee后显示,否则,框架将在jtable和某些jlabel上显示所有费用记录。
我写了这个代码,我没有得到任何错误,但当我运行文件,我得到了所有的学生费用记录,但当我点击jcheckbox只今年的费用没有发生什么我没有得到今年的费用记录。我的代码有什么问题吗?请帮忙。
private void rSButtonIconDsearchstidActionPerformed(java.awt.event.ActionEvent evt) {
try {
Date d = new Date();
int year = d.getYear();
int currentYear = year + 1900;
boolean thisyrchecboxisSelected = jCheckBoxonlythisyearfee.isSelected();
String sqlquerystfeeslist;
if (thisyrchecboxisSelected) {
sqlquerystfeeslist = "SELECT * FROM studentrolls, fees WHERE studentrolls.StudentID = ? AND studentrolls.STRollID = fees.STRollID AND studentrolls.BachID = '"
+ currentYear + "' ORDER BY studentrolls.BachID";
} else {
sqlquerystfeeslist = "SELECT * FROM studentrolls, fees WHERE studentrolls.StudentID = ? AND studentrolls.STRollID = fees.STRollID ORDER BY studentrolls.BachID";
}
PreparedStatement preparedStatement = con.prepareStatement(sqlquerystfeeslist);
PreparedStatement pst = con.prepareStatement(sqlquerystfeeslist);
if (!jTextFieldsearchstid.getText().isEmpty()) {
preparedStatement.setString(1, jTextFieldsearchstid.getText());
ResultSet resultSet = preparedStatement.executeQuery();
DefaultTableModel tblModelfee = (DefaultTableModel) jTablestfeeslist.getModel();
tblModelfee.setRowCount(0); // to clear the table before inserting new data
while (resultSet.next()) {
int stfeebalenceint;
int feecostint = Integer.parseInt(resultSet.getString("MontantFrais"));
int paidamountint = Integer.parseInt(resultSet.getString("MontantPayE"));
stfeebalenceint = feecostint - paidamountint;
String feestatus;
if (stfeebalenceint <= 0) {
feestatus = "SOLDE";
} else {
feestatus = "NO SOLDE";
}
String scolaryearfee = resultSet.getString("BachID");
String feetype = resultSet.getString("TypeFrais");
String feecost = String.valueOf(resultSet.getInt("MontantFrais"));
String paidamount = String.valueOf(resultSet.getInt("MontantPayE"));
String stfeebalence = String.valueOf(stfeebalenceint);
String stfeeslistTableData[] = {scolaryearfee, feetype, feecost, paidamount, stfeebalence, feestatus};
tblModelfee.addRow(stfeeslistTableData);
int stTotfeecost = 0;
for (int i = 0; i < jTablestfeeslist.getRowCount(); i++) {
stTotfeecost = stTotfeecost + Integer.parseInt(jTablestfeeslist.getValueAt(i, 2).toString());
}
int stTotpaidamount = 0;
for (int i = 0; i < jTablestfeeslist.getRowCount(); i++) {
stTotpaidamount = stTotpaidamount + Integer.parseInt(jTablestfeeslist.getValueAt(i, 3).toString());
}
int stTotfeebalence;
stTotfeebalence = stTotfeecost - stTotpaidamount;
String stTotfeestatus;
if (stTotfeebalence <= 0) {
stTotfeestatus = "SOLVABLE";
} else {
stTotfeestatus = "INSOLVABLE";
}
jLabelstTotfeecost.setText(Integer.toString(stTotfeecost));
jLabelstTotpaidamount.setText(Integer.toString(stTotpaidamount));
jLabelstTotfeebalence.setText(Integer.toString(stTotfeebalence));
jLabelstTotfeestatus.setText(stTotfeestatus);
}
} else {
JOptionPane.showMessageDialog(this, "Veillez taper le matricule d'un eleve svp.");
}
} catch (Exception exception) {
JOptionPane.showMessageDialog(this, "erreur des donnees: " + exception.getMessage());
}
}
暂无答案!
目前还没有任何答案,快来回答吧!