Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing ResultSet #1

Open
flaffyyeti opened this issue Oct 28, 2020 · 2 comments
Open

Closing ResultSet #1

flaffyyeti opened this issue Oct 28, 2020 · 2 comments

Comments

@flaffyyeti
Copy link

What about closing result set when stream is processed?
I don't see it is closed in JdbcStream, so shall it be handled by invoker?

@juliomarcopineda
Copy link
Owner

juliomarcopineda commented Nov 3, 2020

Hello, I think closing the result set has to be handled outside of JdbcStream.

My intent with this is class is to purely handle the conversion from JDBC ResultSet to a Stream object so anyone can easily use the Java Stream API (or even StreamEx). Any connection management to the SQL database is left to the user.

So for example, you could use a try-with-resources to call the close() method of ResultSet automatically:

// Set up connection and prepared statement

try (ResultSet resultSet = preparedStatement.executeQuery()) {
    long count = JdbcStream.stream(resultSet).count()
    System.out.println(count)
}

I think this is for the best so that the user has the most flexibility handling the connections to the SQL database.

@flaffyyeti
Copy link
Author

I think in your example resultSet won't be closed by default, you need add handler for Stream.onClose with logic that will close the ResultSet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants