Skip to content
Permalink
Browse files

POI Desktop: move some close in finally

  • Loading branch information...
devemux86 committed Aug 12, 2018
1 parent 9ba4cef commit cd7c193ff81e944ad1b204705bae872d8335cf46
@@ -1,5 +1,5 @@
/*
* Copyright 2015 devemux86
* Copyright 2015-2018 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -63,9 +63,11 @@ private void loadCategories(Connection conn) throws UnknownPoiCategoryException
// Maps categories to their parent IDs
Map<PoiCategory, Integer> parentMap = new HashMap<>();

PreparedStatement stmt = null;
ResultSet rs = null;
try {
PreparedStatement stmt = conn.prepareStatement(SELECT_STATEMENT);
ResultSet rs = stmt.executeQuery();
stmt = conn.prepareStatement(SELECT_STATEMENT);
rs = stmt.executeQuery();
while (rs.next()) {
// Column values
int categoryID = rs.getInt(1);
@@ -83,10 +85,19 @@ private void loadCategories(Connection conn) throws UnknownPoiCategoryException
maxID = categoryID;
}
}
rs.close();
stmt.close();
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
}

// Set root category and remove it from parents map
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 devemux86
* Copyright 2015-2018 devemux86
* Copyright 2017 Gustl22
*
* This program is free software: you can redistribute it and/or modify it under the
@@ -520,14 +520,22 @@ public boolean isValidDataBase() {
// Check for table names
// TODO Is it necessary to get the tables meta data as well?
int numTables = 0;
ResultSet rs = null;
try {
ResultSet rs = this.isValidDBStatement.executeQuery();
rs = this.isValidDBStatement.executeQuery();
if (rs.next()) {
numTables = rs.getInt(1);
}
rs.close();
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
}

if (version < 2) {
@@ -544,12 +552,13 @@ public boolean isValidDataBase() {
public void readPoiFileInfo() {
PoiFileInfoBuilder poiFileInfoBuilder = new PoiFileInfoBuilder();

ResultSet rs = null;
try {
if (this.metadataStatement == null) {
this.metadataStatement = this.conn.prepareStatement(DbConstants.FIND_METADATA_STATEMENT);
}

ResultSet rs = this.metadataStatement.executeQuery();
rs = this.metadataStatement.executeQuery();
while (rs.next()) {
String name = rs.getString(1);

@@ -580,9 +589,16 @@ public void readPoiFileInfo() {
break;
}
}
rs.close();
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
}

poiFileInfo = poiFileInfoBuilder.build();

0 comments on commit cd7c193

Please sign in to comment.
You can’t perform that action at this time.