Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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();
            }



        }
Posted
Updated 8-Mar-17 19:50pm
v2

Use this:
Java
String query1="select total(Amount) As TotalAmt from enquiry where `client`= ?";

then
Java
String s=r.getString("TotalAmt)");
 
Share this answer
 
to add to solution 1, shouldn't it be
sum(Amount)
instead of
total(Amount)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900