Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the value

 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • 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
 
Ramasamy Anbalagan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you for the reply
It works
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ramasamy It works..
 
xsunil kumar
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you for the responce
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic