import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class C3P0Example {
private static ComboPooledDataSource dataSource;
static {
dataSource = new ComboPooledDataSource();
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/mydb");
dataSource.setUser("username");
dataSource.setPassword("password");
dataSource.setMaxPoolSize(100);
dataSource.setMinPoolSize(10);
dataSource.setMaxIdleTime(60);
dataSource.setCacheStatement(true);
dataSource.setPreferredTestQuery("SELECT 1");
dataSource.setTestConnectionOnCheckout(true);
}
public static Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
}