Mark Guo wrote:Hi friends
I have a question for releasing the memory of Statement.
Statement stmt = conn.createStatement();
Whether the "stmt.close()" can release the memory of stmt object or "stmt = null" can release the memory of stmt object ? I'm not sure.
Thanks in advance!
~Bill
The Connection encapsulates database connection functionality, the Statement encapsulates SQL queries and execution.
FYI, if you are using a mature connection pool (e.g. in WebLogic or JBoss) and prepared statements, the whole situation might be moot. Servers can maintain a cache of the prepared statements, so "close" just closes a wrapper object. Basically you are just telling the server you are done with using the cached object.
The most important objects to close when you are done is ResultSet and some of the JDBC metadata objects. Those are associated with database cursors. If you invoke multiple queries before closing a connection but fail to close cursors between queries, you can run out of cursors pretty rapidly. If you are just doing a single query and then closing the connection, there is no need to explicitly close statements and result sets because the connection close automatically closes all open JDBC objects associated with the connection.
The reason I say its good practice... For example, if for some reason you are using a "primitive" type of database pooling and you call connection.close(), the connection will be returned to the pool and the ResultSet/Statement will never be closed and then you will run into many different new problems!
So you can't always count on connection.close() to clean up.
Vanja Sanjin wrote:Sorry.
~Bill
Vanja Sanjin wrote:Thanks. I feel easier. [edit] becaouse I was not sure
~Bill
Vanja Sanjin wrote:: ) Me too (I laughed a bit from happines, thanks)
~Bill
Don't get me started about those stupid light bulbs. |