michele
michele

Reputation: 26598

Oracle JDBC Datasource set auto commit property to false to all connections

I have this bean:

public DataSource getDatsource() throws SQLException {
    OracleDataSource dataSource = new OracleDataSource();
    dataSource.setUser(userName);
    dataSource.setPassword(password);
    dataSource.setURL(wallet);
    Properties props = new Properties();
    props.put("AutoCommit", false); // not working
    dataSource.setConnectionProperties(props );
    return dataSource;
}

I would set up datasource like all the connection generated from it, has auto commit to false.

How can I do it?

PS I know -Doracle.jdbc.autoCommitSpecCompliant=false and works, but I would set the property hard coded.

Thanks.

Upvotes: 0

Views: 3901

Answers (2)

p3consulting
p3consulting

Reputation: 4640

The value should be a String not a Boolean:

props.put(OracleConnection.CONNECTION_PROPERTY_AUTOCOMMIT, "false"); 

Upvotes: 0

michele
michele

Reputation: 26598

Solution:

public DataSource getDefaultDataSource() throws SQLException {
    OracleDataSource dataSource = new OracleDataSource();
    dataSource.setUser(userName);
    dataSource.setPassword(password);
    dataSource.setURL(wallet);
    Properties props = new Properties();
    props.put("oracle.jdbc.autoCommitSpecCompliant", "false");
    dataSource.setConnectionProperties(props );
    return dataSource;
}

Upvotes: 1

Related Questions