プリペアドステートメントを使用したクロス集計クエリ(postgresを使用)があります(中央)パラメーターを追加しようとしていますが、機能していません。コードは次のとおりです。
public List<openbookBean> summarylist(String center) throws SQLException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
String querystring = "select team_manager as team_manager2, "
+ "compliance_1 as day1, "
+ "compliance_2 as day2, "
+ "compliance_3 as day3 "
+ "FROM crosstab('select team_manager, date_compliance, compliance from openbook_comp where("
+ "extract(day from date_compliance)= ''1'' or "
+ "extract(day from date_compliance)= ''2'' or "
+ "extract(day from date_compliance)= ''3'') "
+ "and center = '''?''' "
+ "order by 1,2') AS openbook_comp (team_manager text, "
+ "compliance_1 varchar,"
+ "compliance_2 varchar,"
+ "compliance_3 varchar)";
List<openbookBean> summarylist_array = new ArrayList<openbookBean>();
try {
connection = database.getConnection();
statement = connection.prepareStatement(querystring);
statement.setString(1, center);
resultSet = statement.executeQuery();
while (resultSet.next()) {
openbookBean summarylistarray = new openbookBean();
summarylistarray.setTeam_manager2(resultSet.getString("team_manager2"));
summarylistarray.setDay1(resultSet.getString("day1"));
summarylistarray.setDay2(resultSet.getString("day2"));
summarylistarray.setDay3(resultSet.getString("day3"));
summarylist_array.add(summarylistarray);
}
} finally {
try { resultSet.close(); } catch (SQLException logOrIgnore) {}
try { statement.close(); } catch (SQLException logOrIgnore) {}
try { connection.close(); } catch (SQLException logOrIgnore) {}
}
return summarylist_array;
}
}
これがサーブレットの一部です
if (request.getParameter("show").equals("summary")) {
try {
List<openbookBean> summarylist_array = openbookDAO.summarylist(region);
request.setAttribute("summarylist_array", summarylist_array);
request.getRequestDispatcher("summary.jsp").forward(request, response);
}
catch (SQLException e) {
throw new ServletException("Cannot retrieve areas", e);
}
}
私はいつもこのエラーを受け取ります:
java.lang.NullPointerException
source.openbookDAO.summarylist(openbookDAO.java:358)
source.openbookServlet.doGet(openbookServlet.java:74)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)