Languages
[Edit]
EN

Java - how to close resources correctly / objects during MySQL queries with JDBC?

9 points
Created by:
Teilsa
1315

In this article proper way how to release resources working with JDBC has been presented.

1. close() method example

Edit

Result:

Note: data preparation sql can be found here (at the end of article).

2. try-with-resources example 

Edit

Contruction try (Type variable = ...;) { ... } takes care of releasing of all object references that were places inside round brackets (for variable will be called close() method after curly bracket instructions will be finished). To use object with try-with-resources it is necessary to implement AutoCloseable interface by them.

Result:

Note: data preparation sql can be found here (at the end of article).

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - MySQL

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join