private static final String DBVERSION_REGEX = "^([\\d]+\\.[\\d]+\\.[\\d]+)";
private static final Pattern DBVERSION_PATTERN = Pattern.compile(DBVERSION_REGEX);
private static final String SELECT_VERSION_QUERY = "SELECT @@version as version";
- private static final String LOG_PROBLEM_CLOSING_CONNECTION = "problem closing connection: ";
private static final String DBNAME_DEFAULT = "sdnrdb";
private final String dbConnectionString;
} catch (SQLException e) {
LOG.warn("problem reading views: ", e);
}
+ try { data.close(); } catch (SQLException ignore) { }
return list;
}
} catch (SQLException e) {
LOG.warn("problem reading tables: ", e);
}
+ try { data.close(); } catch (SQLException ignore) { }
return list;
}
public boolean createTable(String query) {
boolean result = false;
PreparedStatement stmt = null;
+ Connection connection = null;
try {
- Connection connection = this.getConnection();
+ connection = this.getConnection();
stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
stmt.execute();
- connection.close();
+
result = true;
} catch (SQLException e) {
LOG.warn("problem creating table:", e);
} finally {
- if (stmt != null) {
- try {
- stmt.close();
- } catch (SQLException e) {
- LOG.warn("problem closing stmt:", e);
- }
- }
+ if (stmt != null) try { stmt.close(); } catch (SQLException logOrIgnore) {}
+ if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {}
}
return result;
}
boolean result = false;
SQLException innerE = null;
Statement stmt = null;
- try (Connection connection = this.getConnection()) {
+ Connection connection = null;
+ try {
+ connection= this.getConnection();
stmt = connection.createStatement();
result = stmt.execute(query);
result = stmt.getUpdateCount() > 0 ? stmt.getUpdateCount() > 0 : result;
} catch (SQLException e) {
innerE = e;
} finally {
- try {
- if (stmt != null) {
- stmt.close();
- }
- } catch (SQLException e) {
- LOG.warn(LOG_PROBLEM_CLOSING_CONNECTION, e);
- }
+ if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {}
+ if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
}
if (innerE != null) {
throw innerE;
boolean result = false;
SQLException innerE = null;
PreparedStatement stmt = null;
- try (Connection connection = this.getConnection()) {
+ Connection connection = null;
+ try {
+ connection = this.getConnection();
stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
result = stmt.execute();
result = stmt.getUpdateCount() > 0 ? stmt.getUpdateCount() > 0 : result;
} catch (SQLException e) {
innerE = e;
} finally {
- try {
- if (stmt != null) {
- stmt.close();
- }
- } catch (SQLException e) {
- LOG.warn(LOG_PROBLEM_CLOSING_CONNECTION, e);
- }
+ if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {}
+ if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
}
if (innerE != null) {
throw innerE;
String result = null;
SQLException innerE = null;
PreparedStatement stmt = null;
- try (Connection connection = this.getConnection()) {
+ ResultSet generatedKeys = null;
+ Connection connection = null;
+ try {
+ connection = this.getConnection();
stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
stmt.execute();
- ResultSet generatedKeys = stmt.getGeneratedKeys();
+ generatedKeys = stmt.getGeneratedKeys();
if (generatedKeys.next()) {
result = String.valueOf(generatedKeys.getLong(1));
}
} catch (SQLException e) {
innerE = e;
} finally {
- try {
- if (stmt != null) {
- stmt.close();
- }
-
- } catch (SQLException e) {
- LOG.warn(LOG_PROBLEM_CLOSING_CONNECTION, e);
- }
+ if (generatedKeys != null) try { generatedKeys.close(); } catch (SQLException ignore) {}
+ if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {}
+ if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
}
if (innerE != null) {
throw innerE;
public ResultSet read(String query) {
ResultSet data = null;
Statement stmt = null;
- try (Connection connection = this.getConnection()) {
+ Connection connection = null;
+ try{
+ connection = this.getConnection();
stmt = connection.createStatement();
data = stmt.executeQuery(query);
} catch (SQLException e) {
LOG.warn("problem reading db for query '{}': ", query, e);
} finally {
- try {
- if (stmt != null) {
- stmt.close();
- }
- } catch (SQLException e) {
- LOG.warn(LOG_PROBLEM_CLOSING_CONNECTION, e);
- }
+ if (stmt != null) try { stmt.close(); } catch (SQLException ignore) {}
+ if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
}
return data;
}