Question: Hii Guys!!!,
 I have written a query in MySql which gives the sum of particular field in table column And the Query is 

```
PreparedStatement st = con.prepareStatement("SELECT COUNT(toc) AS std FROM processeddata_table where date(calldate) between '2009-01-01' and '2012-09-01' and toc='std' GROUP BY toc ");

```

Now As per my need i have to store the sum of all 'std' values into a variable for which i have written code like 

```
ResultSet res = st.executeQuery();      
while (res.next())
{
    int std='';
}

```

How to get the sum of the field in variable named "std".

Guys plz help me. Thanx in advance

Answer: 
`int std=res.getInt("std");` should get the value.

As per [ResultSet javadoc](http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#getInt%28java.lang.String%29)

> 
> Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language.
> 
> 
>
You can try either of the below approach ::

```
PreparedStatement st = con.prepareStatement("SELECT COUNT(toc) AS std FROM processeddata_table where date(calldate) between '2009-01-01' and '2012-09-01' and toc='std' GROUP BY toc ");

```

Approach 1 : As Kuya John has pointed :

```
ResultSet res = st.executeQuery();
while (res.next()) 
{
    int std = res.getInt("std");
}

```

Approach 2 ::

```
ResultSet res = st.executeQuery();
while (res.next()) 
{
    int std = res.getInt(1);
}

```