From: varun gudisena Date: Tue, 9 Apr 2019 21:17:21 +0000 (+0000) Subject: Merge "Change this "try" to a try-with-resource" X-Git-Tag: 1.0.26~11 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdbcapi.git;a=commitdiff_plain;h=4444a934c6ad97d0222abc351af4c392d42f654e;hp=e1d69b3467917291b39c915929bda63f52773e83 Merge "Change this "try" to a try-with-resource" --- diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java b/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java index 1f1b078..349bc46 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java @@ -25,7 +25,6 @@ import java.sql.*; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -; public class LoadSchema { private static final EELFLogger logger = EELFManager.getInstance().getLogger(LoadSchema.class); @@ -44,12 +43,12 @@ public class LoadSchema { } static void upgrade() throws SQLException { ConnectionFactory cf = ConnectionFactory.getDefaultInstance(); - Connection c = null; - Statement stmt = null; InputStream is = null; - try { - c = cf.get(true); - stmt = c.createStatement(); + try( + Connection c = cf.get(true); + Statement stmt = c.createStatement(); + ) { + // this sets the PG search_path to a consistent schema, otherwise sometimes // we get public, and sometimes we get dmaap_admin @@ -120,21 +119,6 @@ public class LoadSchema { } } catch (IOException ioe) { throw new SQLException(ioe); - } finally { - if (stmt != null) { - try { - stmt.close(); - } catch (Exception e) { - logger.error("Error", e); - } - } - if (c != null) { - try { - c.close(); - } catch (Exception e) { - logger.error("Error", e); - } - } } } public static void main(String[] args) throws Exception {