Added sonar fixes in StatisticsServlet.java
[dmaap/datarouter.git] / 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