And a great answer I might say.

Thanks.

-S

-----Original Message-----
From: Phil Steitz [mailto:[email protected]] 
Sent: Thursday, September 17, 2015 2:42 PM
To: Commons Users List
Subject: Re: [dbcp] inconsistently set autocommit

On 9/16/15 10:35 AM, Pruitt, Byron S wrote:
> My usual process for learning something is a quick prototype.  For setting up 
> a driver pool with autocommit = false, I implemented the little quickie 
> prototype below.
>
> Properties dbProp = new Properties();
> dbProp.put("user", "aUser");
> dbProp.put("password", "aPw");
> dbProp.put("loginTimeout", "35");
> dbProp.put("binaryBatchInsert", "true"); dbProp.put("autocommit", 
> false); DataSource dataSource = setupDataSource("myConnectURI", 
> dbProp);  //this the standard example on the website
>
> Connection conn = dataSource.getConnection();
> System.out.println("autocommit: " + conn.getAutoCommit());   //this prints 
> out false
>
> Next.
> I moved the above code verbatim to my actual server code.
> The first connection I get from the pool has autocommit == false.  I return 
> this connection back to the pool.
> But the second time I get a connection from the pool it has autocommit == 
> true.
>
> I have no idea why autocommit is set to a different state for the second 
> connection?  I can do a test and then set to autocommit = false, but I would 
> like to understand the inconsistency.

Great question.  By default, DBCP's PoolableConnectFactory sets autocommit to 
true when it returns a connection to the pool.  See
DBCP-97 for the rationale for this default behavior.  This behavior can be 
modified by setting the enableAutoCommitOnReturn of BasicDataSource or 
PoolableConnectionFactory to false.  You can also use the defaultXxx properties 
of BDS or PCF to set default properties for connections supplied by the pool.  
These properties ensure that connections will be restored to a consistent state 
when the are checked out from the pool, even if client code has mutated them 
while the connection has been checked out.

Phil
>
> Thanks.
>
> Steve Pruitt
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to