I am using Spring NamedParameterJdbcTemplate to retrieve some values ββfrom a table. For some reason, the query runs very slowly in my Java application, and not in the same query in SQL Management Studio. I also noticed in the profiler that prepared statements are not reused. If I run the same query in my JAVA application several times, I see different prepared statements. Therefore, I do not know why applications are not reused. Is performance slow because I use the IN clause in my query?
Here is sample Java code
StringBuilder vQuery = new StringBuilder();
vQuery.append(" SELECT SUM(Qty) FROM vDemand");
vQuery.append(" WHERE ProductID = :ProductID");
vQuery.append(" AND [Date] >= :StartDate AND [Date] <= :EndDate");
vQuery.append(" AND CustomerID IN ( :CustomerID )");
MapSqlParameterSource vNamedParameters = new MapSqlParameterSource();
vNamedParameters.addValue("ProductID", aProductID);
vNamedParameters.addValue("CustomerID", aCustomerlIDs);
vNamedParameters.addValue("StartDate", aDate, Types.TIMESTAMP);
vNamedParameters.addValue("EndDate", aDate, Types.TIMESTAMP);
int vTotalQuantity = this.getNamedParameterJdbcTemplate().queryForInt(vQuery.toString(), vNamedParameters);
return vTotalQuantity;
source
share