0
このクエリを実行しても接続が終了せず、原因を特定できません。 はここ クエリ終了後にdbへの接続が閉じられない
は私が問題を把握助けてください接続の数は、(私は、接続が閉じられていない知っている理由です)のショーのスクリーンショットです。
@Override
public Map<MenuItem, Long> getGtinFromIngredientByLinkedProduct(Map<Long, MenuItem> ingredientIdProductMap) {
Map<MenuItem, Long> result = new HashMap<MenuItem, Long>();
String sql = "SELECT INGREDIENTS_GLOBAL_TRACK_IDF, INGREDIENT_ID FROM [PWRNXGDTA].INGREDIENTS WHERE INGREDIENT_ID in (";
StringBuilder ingredientsIDs = new StringBuilder();
boolean first = true;
Set<Long> ingredients = ingredientIdProductMap.keySet();
System.out.println("Ingredient id's SIZE: " + ingredients.size());
for(Long ingredientId : ingredients) {
if(!first){
ingredientsIDs.append(",");
} else {
first = false;
}
ingredientsIDs.append(ingredientId);
}
sql+= ingredientsIDs+")";
Connection con = null;
PreparedStatement ps = null;
QueryRunner q = null;
ResultSet rs = null;
try {
q = super.getQueryRunner();
con = q.getDataSource().getConnection();
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
result.put(ingredientIdProductMap.get(rs.getLong("INGREDIENT_ID")),
rs.getLong("INGREDIENTS_GLOBAL_TRACK_IDF"));
}
} catch (DAOException | SQLException e) {
logger.info(e.getMessage());
}
finally {
try {
if(ps != null){
ps.close();
}
if(con != null) {
con.close();
}
if(q != null) {
q.getDataSource().getConnection().close();
}
if(rs != null) {
rs.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return result;
}
任意のアイデア:
これはコードのですか?
おかげで、あなたのfinallyブロックで
接続を閉じるときにログに例外が発生していることが明らかになっていますか?ところで、接続前に結果セットを閉じるべきであると私は確信しています。 –
例外はありません... –
私は以下の答えで打ちました。間違っていても、それはあなたが排除することができます。 –