Note that there are some explanatory texts on larger screens.

plurals
  1. POsum of columns in database table returning 0
    primarykey
    data
    text
    <p>I am using mySql database.</p> <p>I created a method to calculate the sum of a column. It is working fine.</p> <pre><code>public int calculate(String department) { int sum = 0; try { BaseDao baseDao = new BaseDao(); Connection connection = baseDao.getConnection(); String query = "select sum(Allocation) from test.Employee where Department=?"; PreparedStatement preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, department); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { int c=resultSet.getInt(1); sum = sum+c; } System.out.println(sum); }catch(Exception e) { e.printStackTrace(); } return sum; } </code></pre> <p>I also created another method in which i am calculating sum of columns and also i mentioned a two conditions, but it is not working. It is showing the sum is 0.</p> <pre><code> public int calculate2(String managerId, String managerId2) { int sum = 0; try { BaseDao baseDao = new BaseDao(); Connection connection = baseDao.getConnection(); String query = "select sum(Allocation) from test.Employee where EmployeeId=? and Manager=?"; PreparedStatement preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, managerId); preparedStatement.setString(2, managerId2); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { int c = resultSet.getInt(1); sum=sum+c; } System.out.println(sum); }catch(Exception e) { e.printStackTrace(); } return sum; } </code></pre> <p>Here is the error log</p> <pre><code>Oct 03, 2013 9:06:22 PM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/SavvisProject] has started Oct 03, 2013 9:06:22 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc SEVERE: The web application [/SavvisProject] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Oct 03, 2013 9:06:23 PM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/SavvisProject] is completed </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload