Should I keep DB connection open or close?
- Should I close database connection?
- What happens if I dont close DB connection?
- Should we close connection in connection pool?
- Should you close connection after every query?
Should I close database connection?
If you do not close your database connections, many problems can occur like web pages hanging, slow page loads, and more.
What happens if I dont close DB connection?
If you don't close it, it leaks, and ties up server resources. @EJP The connection itself might be thread-safe (required by JDBC), but the applications use of the connection is probably not threadsafe. Think of things like different transaction isolation, boundaries (commit/rollback/autocommit) etc.
Should we close connection in connection pool?
Yes, certainly you need to close the pooled connection as well. It's actually a wrapper around the actual connection. It wil under the covers release the actual connection back to the pool.
Should you close connection after every query?
Nothing bad will happen. But if you constantly open/close the connection, you're doing the TCP handshake, forcing the OS to allocate file descriptor and CPU has to do more work because OS constantly creates a new thread for each connection you create/destroy. That's extremely wasteful.
Related Questions
-
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago