ResultSet rst = stmt.executeQuery();
PreparedStatement preparedStatement;
while (rst.next()) {
Integer languageId = rst.getInt("language_id");
Map<String, List<UserMessageItem>> listUserMessageItem = new HashMap<String, List<UserMessageItem>>();
*preparedStatement = connection.prepareStatement(query);*// first assignation of preparedStatement
preparedStatement.setInt(1, languageId);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
//do stuff
} else {
//do else stuff
}
*preparedStatement = connection.prepareStatement(DictionaryManager.LOAD_MAX_MESSAGE_ID);*//other assignation of preparedStatement
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
maxMessageId = resultSet.getInt("MAX(message_id)");
}
resultSet.close();
preparedStatement.close();
rst.close();
stmt.close();
我必须重构这些东西......请不要关心尝试捕获的遗漏最终阻止...任何我想问你:我应该在分配新的prepareStatement之前关闭preparedStatement吗?
答案 0 :(得分:2)
每次都必须关闭它。重新分配它会创建一个新的并释放旧的。