本文介绍了在java中从数据库中提取值的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示文本字段中的金额总和,但是要从数据库中提取金额。这里我尝试了这段代码但文本字段中只有0.0显示... Dint得到实际金额。
我尝试过:
I want to display sum of amount in textfield but amount fetching from database..Here I tried this code but only 0.0 displays in textfield...Dint get actual amount.
What I have tried:
try
{
String t= (String)client.getSelectedItem(); //client = JCombobox
String query1="select total(Amount) from enquiry where `client`= ?";
PreparedStatement p=conn.prepareStatement(query1);
p.setString(1,tfsum.getText()); //tfsum = textfield whr sum will displays
ResultSet r=p.executeQuery();
if(r.next())
{
String s=r.getString("total(Amount)");
tfsum.setText(s);
}
r.close();
p.close();
}
catch(Exception d)
{
d.printStackTrace();
}
}
推荐答案
String query1="select total(Amount) As TotalAmt from enquiry where `client`= ?";
则
then
String s=r.getString("TotalAmt)");
sum(Amount)
而不是
total(Amount)
这篇关于在java中从数据库中提取值的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!