diff options
author | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-08-29 20:41:19 +0530 |
---|---|---|
committer | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-08-29 20:47:07 +0530 |
commit | c3e6bf5bde573fe733f5b5860610d3df73630014 (patch) | |
tree | 8517e77d260dc30228200187cf659095d1b3391e | |
parent | 04dd60b7f0ebdadd5af0a4147a3e601734d6e3dc (diff) |
Fixed Sonar Blocker in StatisticsServlet
Fixed 4 Blocker issues in StatisticsServlet.java
https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=
AWHFaQmXEU5FCDfKtnMB&resolved=false&severities=BLOCKER&types=BUG
https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=
AWHFaQmXEU5FCDfKtnL-&resolved=false&severities=BLOCKER&types=BUG
https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=
AWHFaQmXEU5FCDfKtnL_&resolved=false&severities=BLOCKER&types=BUG
https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open
=AWHFaQmXEU5FCDfKtnMA&resolved=false&severities=BLOCKER&types=BUG
Issue-ID: DMAAP-674
Change-Id: I3dbc50523e0fda002c0a26fa05b23814bf8563bc
Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
-rwxr-xr-x | datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java | 91 |
1 files changed, 48 insertions, 43 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java index 134a595b..e79d4705 100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java @@ -293,13 +293,13 @@ public class StatisticsServlet extends BaseServlet { /**
* getFeedIdsByGroupId - Getting FEEDID's by GROUP ID.
*
- * @throws SQL Query SQLException.
+ * @throws SQLException Query SQLException.
*/
public StringBuffer getFeedIdsByGroupId(int groupIds) throws SQLException {
DB db = null;
Connection conn = null;
- PreparedStatement prepareStatement = null;
+ //PreparedStatement prepareStatement = null;
ResultSet resultSet = null;
String sqlGoupid = null;
StringBuffer feedIds = new StringBuffer();
@@ -308,16 +308,16 @@ public class StatisticsServlet extends BaseServlet { db = new DB();
conn = db.getConnection();
sqlGoupid = " SELECT FEEDID from FEEDS WHERE GROUPID = ?";
- prepareStatement = conn.prepareStatement(sqlGoupid);
- prepareStatement.setInt(1, groupIds);
- resultSet = prepareStatement.executeQuery();
- while (resultSet.next()) {
- feedIds.append(resultSet.getInt("FEEDID"));
- feedIds.append(",");
+ try(PreparedStatement prepareStatement = conn.prepareStatement(sqlGoupid)) {
+ prepareStatement.setInt(1, groupIds);
+ resultSet = prepareStatement.executeQuery();
+ while (resultSet.next()) {
+ feedIds.append(resultSet.getInt("FEEDID"));
+ feedIds.append(",");
+ }
+ feedIds.deleteCharAt(feedIds.length() - 1);
+ System.out.println("feedIds" + feedIds.toString());
}
- feedIds.deleteCharAt(feedIds.length() - 1);
- System.out.println("feedIds" + feedIds.toString());
-
} catch (SQLException e) {
e.printStackTrace();
} finally {
@@ -326,13 +326,7 @@ public class StatisticsServlet extends BaseServlet { resultSet.close();
resultSet = null;
}
-
- if (prepareStatement != null) {
- prepareStatement.close();
- prepareStatement = null;
- }
-
- if (conn != null) {
+ if (conn != null) {
db.release(conn);
}
} catch (Exception e) {
@@ -571,33 +565,44 @@ public class StatisticsServlet extends BaseServlet { intlogger.info("Error parsing time=" + s);
return -1;
}
-
-
private ResultSet getRecordsForSQL(String sql) {
- intlogger.debug(sql);
- long start = System.currentTimeMillis();
- DB db = new DB();
- Connection conn = null;
- ResultSet rs = null;
-
- try {
- conn = db.getConnection();
- Statement stmt = conn.createStatement();
- PreparedStatement pst = conn.prepareStatement(sql);
- rs = pst.executeQuery();
- //this.rsToJson(rs)
- //rs.close();
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (conn != null) {
- db.release(conn);
- }
- }
+ intlogger.debug(sql);
+ long start = System.currentTimeMillis();
+ DB db = new DB();
+ Connection conn = null;
+ ResultSet rs = null;
+ Statement stmt = null;
+ PreparedStatement pst = null;
+ try {
+ conn = db.getConnection();
+ stmt = conn.createStatement();
+ pst = conn.prepareStatement(sql);
+ rs = pst.executeQuery();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ } finally {
+
+ try {
+ if (conn != null) {
+ db.release(conn);
+ }
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (pst != null) {
+ pst.close();
+ }
+ if (rs != null) {
+ rs.close();
+ }
+
+ } catch (SQLException sqlException) {
+ intlogger.error("Exception in getting SQl Records",sqlException);
+ }
- intlogger.debug("Time: " + (System.currentTimeMillis() - start) + " ms");
+ intlogger.debug("Time: " + (System.currentTimeMillis() - start) + " ms");
- return rs;
+ return rs;
+ }
}
}
|