Re: Why we have to close connection, statement, prepared statement
once we aquire the result.we no more need the connection.So inorder to improve safety of u r application and performance u need to close the connection.
Re: Why we have to close connection, statement, prepared statement
not closing connections to DB server will soon result in no managed connections available exception i.e. other threads/programs needing to use connections will not find any as all connections are already in use (not closed)
Re: Why we have to close connection, statement, prepared statement
As per my understanding:
while a connection object is created, it locks the database. related to that connection object. when the developer does not close the connection, the lock to the database will not be released. so no other thread can access the database.
when a statement object is created, it locks the table.
same as when resultset object is created, it locks the row.
when these objects are not closed after use, these locks will never ve released. hence reduces the performance.