Why is it important to open JDBC connections using the try-with-resources (try (…){ … } ) syntax?
Why is it important to open JDBC connections using the try-with-resources (try
(…){ … } ) syntax?
The resource is such type of object that must be closed after finishing the program.
It is a guarantee, when you will use the try-with-resources statement, it will close each and every resource at the end of statement execution.
You don't need to close resource, when you will use the try-with-resources statement in your code, it will get closed implicitly.
In JDBC connections, you need to write code for opening and closing connections.
But if you will write the try-with-resources statement then you won't write code for closing the connection explicitly.
So try-with-resources statement is important while opening JDBC connections.
Step by step
Solved in 2 steps