Fix jdbc code: Both PreparedStatements must be closed in any case
Change-Id: Ie25aff78e9f74497a36faca97a38737c0d8f4b73
This commit is contained in:
@@ -199,33 +199,27 @@ public class Schema_77 extends SchemaVersion {
|
|||||||
|
|
||||||
static LegacyLabelTypes getLegacyTypes(ReviewDb db) throws SQLException {
|
static LegacyLabelTypes getLegacyTypes(ReviewDb db) throws SQLException {
|
||||||
List<LegacyLabelType> types = Lists.newArrayListWithCapacity(2);
|
List<LegacyLabelType> types = Lists.newArrayListWithCapacity(2);
|
||||||
Statement catStmt = null;
|
Statement catStmt = ((JdbcSchema) db).getConnection().createStatement();
|
||||||
PreparedStatement valStmt = null;
|
|
||||||
ResultSet catRs = null;
|
|
||||||
try {
|
try {
|
||||||
catStmt = ((JdbcSchema) db).getConnection().createStatement();
|
ResultSet catRs = catStmt.executeQuery(
|
||||||
catRs = catStmt.executeQuery(
|
|
||||||
"SELECT category_id, name, abbreviated_name, function_name, "
|
"SELECT category_id, name, abbreviated_name, function_name, "
|
||||||
+ " copy_min_score"
|
+ " copy_min_score"
|
||||||
+ " FROM approval_categories"
|
+ " FROM approval_categories"
|
||||||
+ " ORDER BY position, name");
|
+ " ORDER BY position, name");
|
||||||
valStmt = ((JdbcSchema) db).getConnection().prepareStatement(
|
PreparedStatement valStmt = ((JdbcSchema) db).getConnection().prepareStatement(
|
||||||
"SELECT value, name"
|
"SELECT value, name"
|
||||||
+ " FROM approval_category_values"
|
+ " FROM approval_category_values"
|
||||||
+ " WHERE category_id = ?");
|
+ " WHERE category_id = ?");
|
||||||
|
try {
|
||||||
while (catRs.next()) {
|
while (catRs.next()) {
|
||||||
String id = catRs.getString("category_id");
|
String id = catRs.getString("category_id");
|
||||||
valStmt.setString(1, id);
|
valStmt.setString(1, id);
|
||||||
List<LabelValue> values = Lists.newArrayListWithCapacity(5);
|
List<LabelValue> values = Lists.newArrayListWithCapacity(5);
|
||||||
ResultSet valRs = valStmt.executeQuery();
|
ResultSet valRs = valStmt.executeQuery();
|
||||||
try {
|
|
||||||
while (valRs.next()) {
|
while (valRs.next()) {
|
||||||
values.add(new LabelValue(
|
values.add(new LabelValue(
|
||||||
valRs.getShort("value"), valRs.getString("name")));
|
valRs.getShort("value"), valRs.getString("name")));
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
valRs.close();
|
|
||||||
}
|
|
||||||
LegacyLabelType type =
|
LegacyLabelType type =
|
||||||
new LegacyLabelType(getLabelName(catRs.getString("name")), values);
|
new LegacyLabelType(getLabelName(catRs.getString("name")), values);
|
||||||
type.setId(id);
|
type.setId(id);
|
||||||
@@ -235,16 +229,11 @@ public class Schema_77 extends SchemaVersion {
|
|||||||
types.add(type);
|
types.add(type);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (valStmt != null) {
|
|
||||||
valStmt.close();
|
valStmt.close();
|
||||||
}
|
}
|
||||||
if (catRs != null) {
|
} finally {
|
||||||
catRs.close();
|
|
||||||
}
|
|
||||||
if (catStmt != null) {
|
|
||||||
catStmt.close();
|
catStmt.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return new LegacyLabelTypes(types);
|
return new LegacyLabelTypes(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user