Anonymous Asked in Cars &Transportation · 2 weeks ago

Should I keep DB connection open or close?

If you are talking about a client/server application, I would recommend closing each connection as soon as you are done using it. While each individual application instance might take a small performance hit opening the connection, your application as a whole will scale better. 23 нояб. 2008 г.


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

Relevance
Write us your question, the answer will be received in 24 hours