Fix sonar blocker issue 89/71289/1
authorParshad Patel <pars.patel@samsung.com>
Fri, 26 Oct 2018 03:08:45 +0000 (12:08 +0900)
committerParshad Patel <pars.patel@samsung.com>
Fri, 26 Oct 2018 03:09:02 +0000 (12:09 +0900)
Fix use try with resources issue in RemDbUtils.java

Issue-ID: PORTAL-342
Change-Id: Ibbb134ec9686730cc9dadad88ea60c2bd3286938
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/RemDbUtils.java

index 3a08edc..8e4def2 100644 (file)
@@ -181,19 +181,14 @@ public class RemDbUtils /* implements IDbUtils */{
                try {
                        if (con==null || con.isClosed())  con = getConnection(dbKey); 
                        if(con==null) throw new ReportSQLException("Remote Connection not configured for "+ dbKey);
-                       Statement stmt = con.createStatement();
-                       logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL] " + sql));
-                       ResultSet rs = stmt.executeQuery(sql);
-                       DataSet ds = new DataSet(rs, maxRowLimit);
-                          if(rs!=null) 
-                                       rs.close();
-                          if(stmt!=null)
-                               stmt.close();
-
-                       return ds;
+                       try(Statement stmt = con.createStatement();
+                               ResultSet rs = stmt.executeQuery(sql);){
+                               logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL] " + sql));
+                               return new DataSet(rs, maxRowLimit);
+                       }
                } catch (SQLException e) {
                        throw new ReportSQLException(e.getMessage(), sql, e.getCause());
-               } 
+               }
        } // executeQuery
 
        public static DataSet executeQuery(String sql,String dbKey) throws ReportSQLException {