cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: Access to JDBC Connection
Date Tue, 14 Oct 2014 23:46:25 GMT
Hi Lon,

Some code samples showing how you get and release connection would help to understand your
problem better. But... You can actually bypass dealing with the internals of Cayenne stack
and work with DataSource as you would in a straight JDBC application:

ServerRuntime r = ...
DataSource ds = r.getDataSource("mydatanode");

try(Connection c = ds.getConnection()) {
   // do your thing here.. and the Java will close the connection 
   // on exit from the "try" block

Or you can use SQLTemplate for raw SQL and avoid dealing with connections all together, which
is a preferred way:


On Oct 14, 2014, at 6:54 PM, Lon Varscsak <> wrote:

> Hey all,
> I have some code that executes some raw SQL and historically (with EOF) I
> just get the connection that would normally be used for that editing
> context.  No problems.  So I'm trying to implement that similarly in
> Cayenne, and I'm getting the DataNode's DataSource's connection, and it
> works, but then any subsequent calls (at least within the same request) I
> get a timeout because it's like the connection is being used (even though
> I'm done executing my query) and unavailable to the pool (error:  Can't
> obtain connection. Request timed out. Total used connections: 1)
> I've been using this code with a JDBC Connection for a very long time, and
> I think I'm releasing the resources I create (the Statement).  What could I
> be missing here?  Is there a better way to "checkout" and then "release"
> the connection?
> Thanks,
> Lon

View raw message