我想创建一个函数来向我展示sum
中的Jtextfield
。我不知道如何调用结果?
我的jtextfieldname
是sum_calc
.Ty
public void getSum() {
Connection con =getConnection();
Statement st;
PreparedStatement pst = null;
ResultSet rs;
try{
String qquery=" SELECT sum(Receipt.Sales_Quantity * Receipt.Pro_Price) AS TotalItemsOrdered FROM Receipt";
pst=con.prepareStatement(qquery);
pst.setString(1,sum_calc );
rs=pst.executeQuery();
if(rs.next()){
JOptionPane.showMessageDialog(null, qquery);
}else{
JOptionPane.showMessageDialog(null, "zero");
}
}catch (Exception e) { JOptionPane.showMessageDialog(null, e); }
};
以下是调用函数的button
private void make_Receipt_sumActionPerformed(java.awt.event.ActionEvent evt) {
getSum();
}
答案 0 :(得分:0)
public void getSum() {
Connection con =getConnection();
Statement st;
PreparedStatement pst = null;
ResultSet rs;
try{
String qquery=" SELECT sum(Receipt.Sales_Quantity * Receipt.Pro_Price) AS TotalItemsOrdered FROM Receipt";
pst=con.prepareStatement(qquery);
//pst.setString(1,qquery );
rs=pst.executeQuery();
if(rs.next()){
float TotalItemsOrdered = rs.getFloat("TotalItemsOrdered");
float nvNum=TotalItemsOrdered;
sum_calc.setText(valueOf(nvNum));
JOptionPane.showMessageDialog(null, rs);
}else{
JOptionPane.showMessageDialog(null, "Not Found");
}
}catch (Exception e) { JOptionPane.showMessageDialog(null, e); }
}