From 94ff05ac011b5ec80142a4c9a084415bb21c6aed Mon Sep 17 00:00:00 2001 From: Amaresh Kumar Date: Tue, 4 Sep 2018 18:40:19 +0530 Subject: Fixed Sonar Issues in LogRecord.java https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=AWHFaQo_EU5FCDfKtnZ4&resolved=false&severities=BLOCKER&types=BUG Issue-ID: DMAAP-697 Change-Id: I57f79eeafb839498231f2550101b9f843b3bb20f Signed-off-by: Amaresh Kumar --- .../datarouter/provisioning/beans/LogRecord.java | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java index 1853ee30..70b8e6a0 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java @@ -59,23 +59,23 @@ public class LogRecord extends BaseLogRecord { Connection conn = null; try { conn = db.getConnection(); - Statement stmt = conn.createStatement(); - Iterator iter = bs.getRangeIterator(); - PreparedStatement ps = conn.prepareStatement(sql); - while (iter.hasNext()) { - Long[] n = iter.next(); - ps.setLong(1, n[0]); - ps.setLong(2, n[1]); - ResultSet rs = ps.executeQuery(); - while (rs.next()) { - LogRecord lr = new LogRecord(rs); - os.write(lr.toString().getBytes()); + try(Statement stmt = conn.createStatement()) { + Iterator iter = bs.getRangeIterator(); + try(PreparedStatement ps = conn.prepareStatement(sql)) { + while (iter.hasNext()) { + Long[] n = iter.next(); + ps.setLong(1, n[0]); + ps.setLong(2, n[1]); + try(ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + LogRecord lr = new LogRecord(rs); + os.write(lr.toString().getBytes()); + } + ps.clearParameters(); + } + } } - rs.close(); - ps.clearParameters(); } - ps.close(); - stmt.close(); } catch (SQLException e) { e.printStackTrace(); } finally { -- cgit 1.2.3-korg