summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunder Tattavarada <statta@research.att.com>2018-08-14 20:00:27 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-14 20:00:27 +0000
commit2e2ec498ce80d674c08ef8909adb5e1138b710bd (patch)
treee658c9a79416ad6ecd2a44bf378351fff936f8ea
parentd25fc43a67643f95a09ce347b3a4d4b551e51f94 (diff)
parent14f57f705068c0aa1c417eed93274e98226b00ab (diff)
Merge "Sonar issue try-with-resources"
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RoleServiceImpl.java23
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);
- }
}
}