File tree Expand file tree Collapse file tree
dao/src/main/java/com/iluwatar/dao Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments