package br.com.alura.jdbc.factory; import java.sql.Connection; import java.sql.SQLException;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class ConnectionFactory {
public DataSource dataSource;
public ConnectionFactory() {
ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
comboPooledDataSource.setJdbcUrl("jdbc:mysql://localhost/loja_virtual?useTimezone=true&serverTimezone=UTC");
comboPooledDataSource.setUser("10203040");
comboPooledDataSource.setPassword("root");
this.dataSource = comboPooledDataSource;
}
public Connection recuperarConexao() {
try {
return this.dataSource.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
} Classe de teste package br.com.alura.jdbc;
import br.com.alura.jdbc.view.ProdutoCategoriaFrame;
public class TestaOperacaoComView {
public static void main(String[] args) {
ProdutoCategoriaFrame produtoCategoriaFrame = new ProdutoCategoriaFrame();
produtoCategoriaFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@6e8bfe95 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: java.sql.SQLException: No suitable driver at java.sql/java.sql.DriverManager.getDriver(DriverManager.java:298) at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163) at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)