diff options
author | Sunder Tattavarada <statta@research.att.com> | 2018-08-14 20:00:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-14 20:00:27 +0000 |
commit | 2e2ec498ce80d674c08ef8909adb5e1138b710bd (patch) | |
tree | e658c9a79416ad6ecd2a44bf378351fff936f8ea | |
parent | d25fc43a67643f95a09ce347b3a4d4b551e51f94 (diff) | |
parent | 14f57f705068c0aa1c417eed93274e98226b00ab (diff) |
Merge "Sonar issue try-with-resources"
-rw-r--r-- | ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RoleServiceImpl.java | 23 |
1 files changed, 7 insertions, 16 deletions
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); - } } } |