简体   繁体   中英

why to close Database connection

Why should we close a database connection? what can happen if a connection is left open? does the connection gets closed automatically when app exits?

1) Open connections as late as possible

2) Close connections as soon as possible

The connection itself is returned to the connection pool. Connections are a limited resource. Any new connection you establish that has exactly the same connection string will be able to reuse the connection from the pool.

It's not really necessary to close your database connection. See this question on stackoverflow for a more detailed explanation.

To release the resourcess like handler,we should use DBHelper.close(); to close Database, if you not close database,its may arise problem when you try to reconnect to Database. So to overcome this problem , we must close Database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM