Also, increased number of opened connections, in database server, slows down the app. Later on, 3 users log out of the app, but because you didn't implement connection closing mechanism, those 3 connections remain active, and as a result, your app will not provide any other connection to some other user. For Example: Imagine that your app has 10 database connections and 10 users are active at the same time. If you forget to do so, it will lead your app to connection memory leak. The close() method is used to close the connection. So, this is not a recommended approach.Īnd if I don't close the connection, what will happen?īy closing the connection, objects of Statement and ResultSet will be closed automatically. If database query is having a longer execution time, then other requests for that connection object will have to wait. In this case, you will have only a single database connection. Couldn't it? If I use it like this, what will happen? We just create a connection as a singleton, and use it everywhere.
0 Comments
Leave a Reply. |