manual set the properties of connection manager by c3p0

407 views Asked by At

I get a connection from c3p0 pool for batch insert and i set the autoCommit=false,after using,i put it back to the poll. If the autoCommit=false still valid for this connection?

1

There are 1 answers

2
Steve Waldman On

No. According the the JDBC spec, new Connections are autocommit=true, and c3p0 implements transparent Connection pooling, meaning an application that functions correctly in a c3p0 application should also function correctly using an unpooled Connection source.

If you wish, you can override this behavior by defining a ConnectionCustomizer. Something like...

package mypkg;

import com.mchange.v2.c3p0.AbstractConnectionCustomizer;
import java.sql.Connection;

public class AutocommitConnectionCustomizer extends AbstractConnectionCustomizer {
    @Override
    public void onCheckOut(Connection c, String parentDataSourceIdentityToken) throws Exception {
        c.setAutoCommit( false );
    }
}

Then, in your config...

c3p0.connectionCustomizerClassName=mypkg.AutocommitConnectionCustomizer

I hope this helps!