PreparedStatement
s are (or ought to be) cached by your JDBC driver. See e.g. http://www.mchange.com/projects/c3p0/
This means you should not hold on to one and use between connections, but don't worry, your driver will manage caching for you. Essentially what happens is each connection will cache its own, so if you have 5 connections, you'll have 5 cached copies lying around, which is probably sufficiently small.
Calling prepareStatement
will retrieve from cache if cached and allocate if not. So repeated calls to prepareStatement
are lightweight. This is the correct use of the API.
See e.g. Oracle's docs which is technically Oracle-specific but I believe this information is standard.