cancel
Showing results for 
Search instead for 
Did you mean: 

PreparedStatements after Connection close on DB Pool

Former Member
0 Kudos

Hello,

I have a quick question about prepared statements.

We have a set of databases which have the same datastructure (for different production locations). If I prepare a statement, this one is parsed against the datasource. Afterwards I do my selects with different parameters over the prepared statement and finally close the db connection. This returns the connection to the db pool of the JDBC Connector. But what will happen to the prepared statement? Is this also closed? What if I connect to another Datasource and have the prepared statement already parsed against another DataSource?

What if I get another Connection from the DB Pool with the same DataSource, is the statement then already parsed?

I have searched the internet for answers, but with no success.

Regards,

Kai

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Well, according to the best practices, you have to close the PreparedStatement instance as well. Basically, when executing Connection.close() the connection is really closed; it is not just returning the Connection instance to the DB pool data structure. So nobody will retrieve this instance anymore. When closing the connection the DB driver "promises" to cleanup all the statements and IO buffers associated with that connection. But nobody can guarantee that so in order to be sure everything is fine, just close the statements too.

Kind regards,

Tsvetomir

Former Member
0 Kudos

After closing the connection, I start the whole process again. Getting a DBConnection from the pool and preparing the statement. Is this statement fully parsed against the database or holds the DB the information about the prepared Statement in the cache, that no performance issue occurs?

Thanks for your answer.

Regards,

Kai

Former Member
0 Kudos

Hello,

This is driver dependent.

On the other hand, the parsing is done on the client side. And parsing operation is not a big deal. Don't worry about that.

The performance bottlenecks with the persistence are mostly in the DB itself. The client does not have so much things to do.

Kind regards,

Tsvetomir

Answers (0)