What you have done is perfect and very good practice.
The reason I say its good practice… For example, if for some reason you are using a “primitive” type of database pooling and you call connection.close()
, the connection will be returned to the pool and the ResultSet
/Statement
will never be closed and then you will run into many different new problems!
So you can’t always count on connection.close()
to clean up.
I hope this helps 🙂
Related Contents:
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- How does a PreparedStatement avoid or prevent SQL injection?
- java.sql.SQLException: – ORA-01000: maximum open cursors exceeded
- Using setDate in PreparedStatement
- How to connect to Oracle using Service Name instead of SID
- Java: Insert multiple rows into MySQL with PreparedStatement
- How do I get the size of a java.sql.ResultSet?
- How can I get the SQL of a PreparedStatement?
- JDBC connection failed, error: TCP/IP connection to host failed
- AbstractTableModel GUI display issue
- Get query from java.sql.PreparedStatement [duplicate]
- Cannot issue data manipulation statements with executeQuery()
- How to connect SQLite with Java?
- JDBC MySql connection pooling practices to avoid exhausted connection pool
- IO Error: The Network Adapter could not establish the connection
- Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client
- right syntax to use near ‘?’
- java.sql.SQLException: Column count doesn’t match value count at row 1
- “Loading class com.mysql.jdbc.Driver … is deprecated” message
- Returning a ResultSet
- How to get a value from the last inserted row? [duplicate]
- JDBC Pagination
- Oracle JDBC intermittent Connection Issue
- java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver
- Running a .sql script using MySQL with JDBC
- How to get all table names from a database?
- Should I use java.util.Date or switch to java.time.LocalDate
- PreparedStatement with Statement.RETURN_GENERATED_KEYS
- Why does autoReconnect=true not seem to work?
- Writing a large resultset to an Excel file using POI
- Does the preparedStatement avoid SQL injection? [duplicate]
- JDBC driver throws “ResultSet Closed” exception on empty ResultSet
- JPA SQL Server No Dialect mapping for JDBC type: -9
- UNIX socket implementation for Java? [closed]
- Spring-Boot: How do I set JDBC pool properties like maximum number of connections?
- How to read all rows from huge table?
- Timezones in SQL DATE vs java.sql.Date
- How to write / update Oracle blob in a reliable way?
- How to execute .sql script file using JDBC [duplicate]
- Driver.getConnection hangs using SQLServer driver and Java 1.6.0_29
- JDBC returning MySQLSyntaxError Exception with correct statement
- Connection timeout for DriverManager getConnection
- Getting the Return Value from JDBC MSSQL
- How do I use PostgreSQL JSON(B) operators containing a question mark “?” via JDBC
- oracle.jdbc.driver.OracleDriver ClassNotFoundException
- How can I abort a running JDBC transaction?
- Date columns in SQL-Server (MSSQL-JDBC 3.0) running under Java 1.7.0 retrieved as 2 days in the past
- How to pass Table-Valued parameters from java to sql server stored procedure?
- com.mysql.jdbc.PacketTooBigException
- How to get the number of columns from a JDBC ResultSet?