I have read a little about this on the internet on previous posts, but I have seen different things, so I want to make sure that I am understanding this correctly.
I have an web app server (tomcat). It maintains a persistent conncetion to the database (mypool) that I store in the servlet context. Each time my code needs to access the database it gets its own copy of mypool. So, even though I have several places in my code where I say:
Connection conn = mypool.getConnection();
Am I trully taking advantage of preparedstatements?
I have found articles and posts that says yes, because I am using the same Connection (well, a copy of it).
I have also found articles and posts that say (if I was reading it correctly) only for tat instance of the Conncetion (if I were doing a loop, which executed my sql).
Now that I think about it, objects are handled by reference. So, in theory, that code statement above does use the same connection and can take advantage of PreparedStatements.
Anthony, You are correct that you really have a reference to the pool rather than a copy of it. If there is one connection in the pool, everybody shares that connection. If there are multiple connections, each one gets it's own copy of the prepared statement. Over time, all the connections wind up with a copy.