问题:如何根据表格中选定的原始付款记录获取最新的付款状态
情景:我目前关注的计划部分是关于客户付款余额的管理。
当我选择原始付款信息的特定记录时,我正在处理的程序正在挂起,并且所选记录通过特定MySQL表installation_sales
中的外键引导一系列记录。 ref_isales_id
(引用同一表isales_id
中主键installation_sales
的外键。
因此,这是一个包含客户付款的表格,其中特定客户的原始付款记录是与同一客户即将付款(即余额付款)的模式的第一部分。
注意:所有变量都已分配,无论是否在代码块中。
守则:
private void manageBalancesTableMouseClicked(java.awt.event.MouseEvent evt) {
payBtn.setEnabled(true);
historyBtn.setEnabled(true);
try{
int row = manageBalancesTable.getSelectedRow();
clickedTable = (manageBalancesTable.getModel().getValueAt(row, 0).toString());
conn = MySQLConnect.ConnectDB();
st = conn.createStatement();
rs = st.executeQuery("select isales_id,rce,total_payment,pay_status,pay_amount,remaining_bal,it_id,client_id,ic_id,ref_isales_id from installation_sales where (isales_id='"+clickedTable+"' or ref_isales_id='"+clickedTable+"') and pay_status!='full payment' order by isales_id desc limit 1");
if(rs.next()) {
isales_id=rs.getString("isales_id");
rce=rs.getString("rce");
total_payment=rs.getDouble("total_payment");
pay_status=rs.getString("pay_status");
pay_amount1=rs.getDouble("pay_amount");
remaining_bal=rs.getDouble("remaining_bal");
it_id=rs.getInt("it_id");
client_id=rs.getString("client_id");
ic_id=rs.getString("ic_id");
ref_isales_id=rs.getString("ref_isales_id");
}
/* When I insert this while looping part in the code, the program lags when I run it. */
while (!"0".equals(ref_isales_id)) {
st2 = conn.createStatement();
rs2 = st2.executeQuery("select isales_id,rce,total_payment,pay_status,pay_amount,remaining_bal,it_id,client_id,ic_id,ref_isales_id from installation_sales where ref_isales_id='"+isales_id+"' and pay_status!='full payment' order by isales_id desc limit 1");
if(rs2.next()) {
isales_id=rs.getString("isales_id");
rce=rs.getString("rce");
total_payment=rs.getDouble("total_payment");
pay_status=rs.getString("pay_status");
pay_amount1=rs.getDouble("pay_amount");
remaining_bal=rs.getDouble("remaining_bal");
it_id=rs.getInt("it_id");
client_id=rs.getString("client_id");
ic_id=rs.getString("ic_id");
ref_isales_id=rs.getString("ref_isales_id");
}
}
} catch (Exception e) {
} finally {
try {
conn.close();
} catch (SQLException ex) {
Logger.getLogger(ManageBalancesPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
if(null!=pay_status) switch (pay_status) {
case "reservation fee":
paymentStatusComboBox.removeAllItems();
paymentStatusComboBox.addItem("select payment status...");
paymentStatusComboBox.addItem("down payment");
paymentAmountTextField.setText("");
break;
case "down payment":
paymentStatusComboBox.removeAllItems();
paymentStatusComboBox.addItem("select payment status...");
paymentStatusComboBox.addItem("installment");
paymentStatusComboBox.addItem("full payment");
paymentAmountTextField.setText("");
break;
case "installment":
paymentStatusComboBox.removeAllItems();
paymentStatusComboBox.addItem("select payment status...");
paymentStatusComboBox.addItem("installment");
paymentStatusComboBox.addItem("full payment");
paymentAmountTextField.setText("");
break;
default:
break;
}
}
这是我第一次来到这里,任何帮助都将受到高度赞赏!
答案 0 :(得分:0)
我的猜测是
rs2 = st2.executeQuery(...)
在你的while循环中,你总是得到相同的响应,只查看返回的第一个条目。所以你总是这样说:给我[1,2,3,4],看[1],再询问[1,2,3,4]然后再看[1],因为无穷大因为ref_isales_id = [1] .ref_isales_id并且永远不会满足你的while循环的条件。
答案 1 :(得分:0)
我已经解决了!
private void manageBalancesTableMouseClicked(java.awt.event.MouseEvent evt) {
payBtn.setEnabled(true);
historyBtn.setEnabled(true);
try{
int row = manageBalancesTable.getSelectedRow();
clickedTable = (manageBalancesTable.getModel().getValueAt(row, 0).toString());
conn = MySQLConnect.ConnectDB();
st = conn.createStatement();
rs = st.executeQuery("select isales_id,rce,total_payment,pay_status,pay_amount,remaining_bal,it_id,client_id,ic_id,ref_isales_id from installation_sales where (isales_id='"+clickedTable+"' or ref_isales_id='"+clickedTable+"') and pay_status!='full payment' order by isales_id desc limit 1");
if(rs.next()) {
isales_id=rs.getString("isales_id");
rce=rs.getString("rce");
total_payment=rs.getDouble("total_payment");
pay_status=rs.getString("pay_status");
pay_amount1=rs.getDouble("pay_amount");
remaining_bal=rs.getDouble("remaining_bal");
it_id=rs.getInt("it_id");
client_id=rs.getString("client_id");
ic_id=rs.getString("ic_id");
ref_isales_id=rs.getString("ref_isales_id");
}
while (!"0".equals(ref_isales_id)) {
st2 = conn.createStatement();
rs2 = st2.executeQuery("select isales_id,rce,total_payment,pay_status,pay_amount,remaining_bal,it_id,client_id,ic_id,ref_isales_id from installation_sales where ref_isales_id='"+isales_id+"' and pay_status!='full payment' order by isales_id desc limit 1");
if(rs2.next()) {
isales_id=rs2.getString("isales_id");
rce=rs2.getString("rce");
total_payment=rs2.getDouble("total_payment");
pay_status=rs2.getString("pay_status");
pay_amount1=rs2.getDouble("pay_amount");
remaining_bal=rs2.getDouble("remaining_bal");
it_id=rs2.getInt("it_id");
client_id=rs2.getString("client_id");
ic_id=rs2.getString("ic_id");
ref_isales_id=rs2.getString("ref_isales_id");
} else {
break;
}
}
} catch (Exception e) {
} finally {
try {
conn.close();
} catch (SQLException ex) {
Logger.getLogger(ManageBalancesPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
if(null!=pay_status) switch (pay_status) {
case "reservation fee":
paymentStatusComboBox.removeAllItems();
paymentStatusComboBox.addItem("select payment status...");
paymentStatusComboBox.addItem("down payment");
paymentAmountTextField.setText("");
break;
case "down payment":
paymentStatusComboBox.removeAllItems();
paymentStatusComboBox.addItem("select payment status...");
paymentStatusComboBox.addItem("installment");
paymentStatusComboBox.addItem("full payment");
paymentAmountTextField.setText("");
break;
case "installment":
paymentStatusComboBox.removeAllItems();
paymentStatusComboBox.addItem("select payment status...");
paymentStatusComboBox.addItem("installment");
paymentStatusComboBox.addItem("full payment");
paymentAmountTextField.setText("");
break;
default:
break;
}
}