- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it mandatory to close JDBC connections?
At the end of your JDBC program, it is required explicitly to close all the connections to the database to end each database session. However, if you forget, Java's garbage collector will close the connection when it cleans up stale objects.
Relying on the garbage collection, especially in database programming, is a very poor programming practice. You should make a habit of always closing the connection with the close() method associated with connection object.
To ensure that a connection is closed, you could provide a 'finally' block in your code. A finally block always executes, regardless of an exception occurs or not.
To close a JDBC connection, you should call close() method as:
conn.close();
- Related Articles
- Is it mandatory to register the driver while working with JDBC?
- Is it mandatory to link my Aadhaar with bank account and mobile?
- How to close the ResultSet cursor automatically, after commit in JDBC?
- Is it mandatory to override the default methods of an interface in Java?
- Is it mandatory to mark a functional interface with @FunctionalInterface annotation in Java?
- Where we should close a connection in JDBC and MySQL?
- Is it mandatory to use T for type-parameter, while defining Generics classes/methods in Java?
- How to close a Android notification after the user is clicking on it?
- What is Mandatory access control in information security?
- Mandatory and optional Participation
- What is JDBC Blob data type? how to store and read data from it?
- What is JDBC Clob data type? how to store and read data from it?
- Pseudo mandatory parameters in JavaScript
- Restricting MySQL Connections to Secure Transport
- Why is Aadhaar mandatory in schools for entry-level admissions?

Advertisements