From 14f57f705068c0aa1c417eed93274e98226b00ab Mon Sep 17 00:00:00 2001 From: Arindam Mondal Date: Mon, 16 Jul 2018 16:20:27 +0900 Subject: Sonar issue try-with-resources Modified RoleServiceImpl, replaced Statement with PreparedStatemnent Issue-ID: PORTAL-338 Change-Id: I8d94682abf72080bc63d0e5b6c91e1869629bbc9 Signed-off-by: Arindam Mondal --- .../portalsdk/core/service/RoleServiceImpl.java | 23 +++++++--------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'ecomp-sdk') diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RoleServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RoleServiceImpl.java index 43cac076..d2d35ef5 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RoleServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RoleServiceImpl.java @@ -38,6 +38,7 @@ package org.onap.portalsdk.core.service; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.Iterator; @@ -166,24 +167,14 @@ public class RoleServiceImpl implements RoleService { @Override public void deleteDependcyRoleRecord(String loginId, Long id) { - Connection conn = null; - Statement stmt = null; - try { - conn = getDataSource().getConnection(); - stmt = conn.createStatement(); - String sql = "delete from fn_user_role where role_id = '" + id + "'"; - stmt.executeUpdate(sql); + + String sql = "delete from fn_user_role where role_id =?"; + try( Connection conn = getDataSource().getConnection();PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setLong(1, id); + pstmt.executeUpdate(sql); + } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "deleteDependcyRoleRecord failed", e); - } finally { - try { - if (stmt != null) - stmt.close(); - if (conn != null) - conn.close(); - } catch (SQLException se) { - logger.error(EELFLoggerDelegate.errorLogger, "deleteDependcyRoleRecord failed to close", se); - } } } -- cgit 1.2.3-korg