diff options
author | Ethan Lynn <ethanlynnl@vmware.com> | 2018-05-10 17:32:19 +0800 |
---|---|---|
committer | Ethan Lynn <ethanlynnl@vmware.com> | 2018-05-10 17:38:46 +0800 |
commit | abc7f36067f48884d9830256e286114f92378d06 (patch) | |
tree | 3b262f96fc1475d1dc98265f839e2bb8c14da5b0 /bpmn/MSOURN-plugin/src | |
parent | b3963d8b0901db1cde5ea85f58684e89b76bf0cc (diff) |
Close db connections in finally block
Fix bugs reported by sonar
Change-Id: I0d3445856eb45533d904443b60d75c8aa03e5881
Issue-ID: SO-580
Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
Diffstat (limited to 'bpmn/MSOURN-plugin/src')
-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 */ }
}
}
|