<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.5</version>
</dependency>
properties
c3p0.driverClass=com.mysql.jdbc.Driver
c3p0.jdbcUrl=jdbc:mysql://localhost:3306/mydatabase
c3p0.user=root
c3p0.password=secret
c3p0.minPoolSize=5
c3p0.maxPoolSize=20
c3p0.acquireIncrement=2
c3p0.maxStatements=100
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
public class C3P0Example {
private static ComboPooledDataSource dataSource;
static {
try {
dataSource = new ComboPooledDataSource();
dataSource.setDriverClass("com.mysql.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/mydatabase");
dataSource.setUser("root");
dataSource.setPassword("secret");
dataSource.setMinPoolSize(5);
dataSource.setMaxPoolSize(20);
dataSource.setAcquireIncrement(2);
dataSource.setMaxStatements(100);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
public static void main(String[] args) {
try (Connection connection = getConnection()) {
} catch (SQLException e) {
e.printStackTrace();
}
}
}