Skip to Content
author's profile photo Former Member
Former Member

PreparedStatements after Connection close on DB Pool

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 30, 2008 at 09:31 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.