8000 Merge pull request #611 from mookkiah/issue_587_dao · prog012/java-design-patterns@68d094a · GitHub
[go: up one dir, main page]

Skip to content

Commit 68d094a

Browse files
authored
Merge pull request iluwatar#611 from mookkiah/issue_587_dao
Issue 587 SonarQube reports bugs - Module DAO
2 parents e367e48 + a1a4088 commit 68d094a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public Stream<Customer> getAll() throws Exception {
6565
Connection connection;
6666
try {
6767
connection = getConnection();
68-
PreparedStatement statement = connection.prepareStatement("SELECT * FROM CUSTOMERS");
69-
ResultSet resultSet = statement.executeQuery();
68+
PreparedStatement statement = connection.prepareStatement("SELECT * FROM CUSTOMERS"); //NOSONAR
69+
ResultSet resultSet = statement.executeQuery(); //NOSONAR
7070
return StreamSupport.stream(new Spliterators.AbstractSpliterator<Customer>(Long.MAX_VALUE,
7171
Spliterator.ORDERED) {
7272

@@ -82,7 +82,7 @@ public boolean tryAdvance(Consumer<? super Customer> action) {
8282
throw new RuntimeException(e);
8383
}
8484
}
85-
}, false).onClose(() -> mutedClose(connection));
85+
}, false).onClose(() -> mutedClose(connection, statement, resultSet));
8686
} catch (SQLException e) {
8787
throw new Exception(e.getMessage(), e);
8888
}
@@ -92,8 +92,10 @@ private Connection getConnection() throws SQLException {
9292
return dataSource.getConnection();
9393
}
9494

95-
private void mutedClose(Connection connection) {
95+
private void mutedClose(Connection connection, PreparedStatement statement, ResultSet resultSet) {
9696
try {
97+
resultSet.close();
98+
statement.close();
9799
connection.close();
98100
} catch (SQLException e) {
99101
e.printStackTrace();

0 commit comments

Comments
 (0)
0