Fixed Sonar Issues in LogRecord.java
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / LogRecord.java
index 1853ee3..70b8e6a 100644 (file)
@@ -59,23 +59,23 @@ public class LogRecord extends BaseLogRecord {
         Connection conn = null;\r
         try {\r
             conn = db.getConnection();\r
-            Statement stmt = conn.createStatement();\r
-            Iterator<Long[]> iter = bs.getRangeIterator();\r
-            PreparedStatement ps = conn.prepareStatement(sql);\r
-            while (iter.hasNext()) {\r
-                Long[] n = iter.next();\r
-                ps.setLong(1, n[0]);\r
-                ps.setLong(2, n[1]);\r
-                ResultSet rs = ps.executeQuery();\r
-                while (rs.next()) {\r
-                    LogRecord lr = new LogRecord(rs);\r
-                    os.write(lr.toString().getBytes());\r
+            try(Statement stmt = conn.createStatement()) {\r
+                Iterator<Long[]> iter = bs.getRangeIterator();\r
+                try(PreparedStatement ps = conn.prepareStatement(sql)) {\r
+                    while (iter.hasNext()) {\r
+                        Long[] n = iter.next();\r
+                        ps.setLong(1, n[0]);\r
+                        ps.setLong(2, n[1]);\r
+                        try(ResultSet rs = ps.executeQuery()) {\r
+                            while (rs.next()) {\r
+                                LogRecord lr = new LogRecord(rs);\r
+                                os.write(lr.toString().getBytes());\r
+                            }\r
+                            ps.clearParameters();\r
+                        }\r
+                    }\r
                 }\r
-                rs.close();\r
-                ps.clearParameters();\r
             }\r
-            ps.close();\r
-            stmt.close();\r
         } catch (SQLException e) {\r
             e.printStackTrace();\r
         } finally {\r