mySql データベースを使用しています。
列の合計を計算するメソッドを作成しました。正常に動作しています。
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;
}
また、列の合計を計算する別の方法を作成し、2つの条件についても言及しましたが、機能していません。合計が0であることを示しています。
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;
}
エラーログはこちら
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