diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-05-10 10:50:31 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-05-10 10:50:31 +0000 |
commit | 0833b215e3256ccd56d45430409e676df51602be (patch) | |
tree | d6751b2ef00236b1982b9dad8c4d573c9953ae8d | |
parent | 438db5f9e7a4c39afe6c9b38d12f9939418ba51a (diff) | |
parent | abc7f36067f48884d9830256e286114f92378d06 (diff) |
Merge "Close db connections in finally block"
-rw-r--r-- | bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java b/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java index 1304fc24a7..85f9753634 100644 --- a/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java +++ b/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java @@ -60,14 +60,15 @@ public class URNResource extends AbstractCockpitPluginResource{ public List<URNData> getUrnDataMap()
{
List<URNData> list = new ArrayList();
-
+ PreparedStatement psData = null;
+ ResultSet r = null;
try {
conn = getDBConnection();
- PreparedStatement psData = conn
+ psData = conn
.prepareStatement("select * from MSO_URN_MAPPING order by NAME_");
- ResultSet r = psData.executeQuery();
+ r = psData.executeQuery();
while(r.next())
{
@@ -78,14 +79,15 @@ public class URNResource extends AbstractCockpitPluginResource{ list.add(d);
}
-
- psData.close();
- conn.close();
} catch (Exception e)
{
e.printStackTrace();
+ } finally {
+ try { r.close(); } catch (Exception e) { /* ignored */ }
+ try { psData.close(); } catch (Exception e) { /* ignored */ }
+ try { conn.close(); } catch (Exception e) { /* ignored */ }
}
for(URNData d: list)
@@ -158,24 +160,26 @@ public class URNResource extends AbstractCockpitPluginResource{ nRow.setVer_("1");
final String myKey = key_;
final String myValue = value_;
-
+
+ PreparedStatement psData = null;
msoLogger.debug("----------- START ----------------------");
try {
conn = getDBConnection();
- PreparedStatement psData = conn
+ psData = conn
.prepareStatement("Insert into MSO_URN_MAPPING values ('" + key_ + "', '" + value_ + "', '1')");
psData.executeUpdate();
- psData.close();
- conn.close();
//}
} catch (Exception e)
{
e.printStackTrace();
+ } finally {
+ try { psData.close(); } catch (Exception e) { /* ignored */ }
+ try { conn.close(); } catch (Exception e) { /* ignored */ }
}
// getQueryService().executeQuery("cockpit.urnMap.insertNewRow", nRow, URNData.class);
}
@@ -184,21 +188,22 @@ public class URNResource extends AbstractCockpitPluginResource{ public void getPersistData(URNData d) {
//getQueryService().executeQuery("cockpit.urnMap.persistURNData", d, URNData.class);
-
+ PreparedStatement psData = null;
try {
conn = getDBConnection();
- PreparedStatement psData = conn
+ psData = conn
.prepareStatement("UPDATE MSO_URN_MAPPING set VALUE_ ='"+ d.getURNValue() + "' WHERE NAME_='" + d.getURNName() + "'");
psData.executeUpdate();
- psData.close();
- conn.close();
} catch (Exception e)
{
e.printStackTrace();
+ } finally {
+ try { psData.close(); } catch (Exception e) { /* ignored */ }
+ try { conn.close(); } catch (Exception e) { /* ignored */ }
}
}
|