Re: [c3p0-users] Statement Pooling
Status: Beta
Brought to you by:
swaldman
|
From: Steve W. <swa...@mc...> - 2012-06-26 08:16:15
|
Hi,
Following the jdbc spec, c3p0's statement pooling is transparent to library clients. Client-visible statements cannot be retained across a Connection close. But when PreparedStatements are "closed" by clients, they are retained internally but c3p0's Statement cache. When clients attempt to "recreate" the Statement, the cached object is returned rather than a new instance.
In other words, you can't reuse anything with c3p0, but in fact you reuse everything. Just as you appear to close and reacquire Connections -- but in fact the "reacquired" Connections are withdrawn from a pool -- so too you seem to close an recreate PreparedStatements while you actually withdraw a pooled Statement (presuming you have set maxStatements / maxStatementsPerConnection to sufficient values).
I hope this helps!
Steve
On Jun 26, 2012, at 5:06 AM, sandman1979 wrote:
>
> Forgive me if I missed something somewhere... I am developing an engine to
> operate on databases by generating queries. I have a query cache of my own
> where the datasource/sql make up the key. The value is a subclass of HashMap
> with a PreparedStatement instance variable. I execute the statement,
> process/close the ResultSet, and then close the connection. If I don't close
> the connection, then I will run into a deadlock from waiting for a
> connection to become available. If I do close the connection, then I get an
> error when I try to re-execute because the statement is closed. I already
> wrote the code in Ruby and now I'm porting it to Java for various reasons,
> so I know the logic itself is fine. I know I can checkin the connection
> without closing it by talking to the pool directly, but I would prefer to
> avoid depending directly on the code if at all possible. Plus, I don't know
> if that could cause unusual behavior. Is there some good documentation
> explaining how statement pooling works? I thought that perhaps if I set the
> size in the config, then I could re-use the object that I stored, but that
> is not the case. Any advise would be great. Thanks.
> --
> View this message in context: http://old.nabble.com/Statement-Pooling-tp34063650p34063650.html
> Sent from the c3p0 - users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> c3p0-users mailing list
> c3p...@li...
> https://lists.sourceforge.net/lists/listinfo/c3p0-users
|