diff options
author | Driptaroop Das <driptaroop.das@in.ibm.com> | 2019-03-07 01:29:18 +0530 |
---|---|---|
committer | Driptaroop Das <driptaroop.das@in.ibm.com> | 2019-03-07 01:29:24 +0530 |
commit | dfd5bff0b1c8cf63a13d74e3b5d322741a4c5a30 (patch) | |
tree | fa49d902cf5a8d6e033c4158a8bb72cf1b782068 | |
parent | d6ac6f8b10e90411dd650d6f7a9ee51179e39bfc (diff) |
Change this "try" to a try-with-resource
Change this "try" to a try-with-resource
Issue-ID: DMAAP-1075
Change-Id: I2d5816bdf63301cc28d80250e2507f3a1cb96a0c
Signed-off-by: Driptaroop Das <driptaroop.das@in.ibm.com>
-rw-r--r-- | src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java | 26 |
1 files changed, 5 insertions, 21 deletions
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 { |