Added sonar fixes in StatisticsServlet.java 99/64299/1
authorAmaresh Kumar <kamaresh@in.ibm.com>
Mon, 3 Sep 2018 15:11:47 +0000 (20:41 +0530)
committerAmaresh Kumar <kamaresh@in.ibm.com>
Mon, 3 Sep 2018 15:11:56 +0000 (20:41 +0530)
https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=AWWKm3GexOv3LmQdDLM3&resolved=false&severities=BLOCKER&types=BUG

Issue-ID: DMAAP-694
Change-Id: Ibd5ee6dd784627bc8afa6e26c82e2c2ceb62a9a9
Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java

index e79d470..33bf3a3 100755 (executable)
@@ -569,40 +569,17 @@ public class StatisticsServlet extends BaseServlet {
       intlogger.debug(sql);\r
       long start = System.currentTimeMillis();\r
       DB db = new DB();\r
-      Connection conn = null;\r
       ResultSet rs = null;\r
-      Statement stmt = null;\r
-      PreparedStatement pst = null;\r
-      try {\r
-          conn = db.getConnection();\r
-          stmt = conn.createStatement();\r
-          pst = conn.prepareStatement(sql);\r
-          rs = pst.executeQuery();\r
+      try (\r
+          Connection conn = db.getConnection()){\r
+          try(PreparedStatement pst = conn.prepareStatement(sql)){\r
+              rs = pst.executeQuery();\r
+          }\r
       } catch (SQLException e) {\r
           e.printStackTrace();\r
-      } finally {\r
-\r
-          try {\r
-              if (conn != null) {\r
-                  db.release(conn);\r
-              }\r
-              if (stmt != null) {\r
-                  stmt.close();\r
-              }\r
-              if (pst != null) {\r
-                  pst.close();\r
-              }\r
-              if (rs != null) {\r
-                  rs.close();\r
-              }\r
-\r
-          } catch (SQLException sqlException) {\r
-              intlogger.error("Exception in getting SQl Records",sqlException);\r
-          }\r
-\r
+      }\r
           intlogger.debug("Time: " + (System.currentTimeMillis() - start) + " ms");\r
-\r
           return rs;\r
       }\r
   }\r
-}\r
+\r