• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get the value

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a problem getting the value of the stm.

In the below code I have used sum to get the added value of the column qty_pcs.

PreparedStatement stm=con.prepareStatement("select SUM(qty_pcs) from inward where parti=?");
stm.setString(1, itm);
stm.executeQuery();

Now how will I get the sum value assigned to a integer variable

Thank you in advance
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can try it by following code snippet

int sumval;
ResultSet rs=null;
PreparedStatement stm=con.prepareStatement("select SUM(qty_pcs) from inward where parti=?");
stm.setString(1, itm);
rs=stm.executeQuery();
if(rs.next()){

sumval=Integer.parseInt(rs.getString(1));

}
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the reply
It works
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ramasamy It works..
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you Initialized the connection object. Before the statement

PreparedStatement stm=con.prepareStatement("select SUM(qty_pcs) from inward where parti=?");
check whether connection is present or not. You can check by using below code

if(con==null)
System.out.println("not connected");
else
System.out.println("connected");

-Sunil
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the responce
 
reply
    Bookmark Topic Watch Topic
  • New Topic