Boa noite, após ter colocado as .jars c3p0-0.9.5.4 e mchange-commons-java-0.2.16, fiz a atualização na Connection e ficou assim como na aula
import com.mchange.v2.c3p0.ComboPooledDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class ConnectionFactory {
public DataSource dataSource;
public ConnectionFactory(){
ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
comboPooledDataSource.setJdbcUrl("jdbc:mysql://localhost/load_virtual?useTimezone=true&serverTimezone=UTC");
comboPooledDataSource.setUser("root");
comboPooledDataSource.setPassword("0490");
comboPooledDataSource.setMaxPoolSize();
this.dataSource = comboPooledDataSource;
}
public Connection recuperarConexao() throws SQLException {
return this.dataSource.getConnection();
}
}
Logo, fui fazer o teste de conexão, com a classe TestaPoolConexoes, que ficou assim:
import java.sql.SQLException;
public class TestaPoolConexoes {
public static void main(String[] args) throws SQLException {
ConnectionFactory connectionFactory = new ConnectionFactory();
for (int i = 0; i<20; i++){
connectionFactory.recuperarConexao();
System.out.println("Conexao de numero"+ i);
}
}
}
Deu um erro gigante e nao consegui resolver, procurei em todos os lugares segue o erro:
abr 26, 2022 10:16:33 PM com.mchange.v2.log.MLog
INFO: MLog clients using java 1.4+ standard logging.
abr 26, 2022 10:16:34 PM com.mchange.v2.c3p0.C3P0Registry
INFO: Initializing c3p0-0.9.5.4 [built 23-March-2019 23:00:48 -0700; debug? true; trace: 10]
abr 26, 2022 10:16:34 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge0yxaot0qffg5ruoek|7e9a5fbe, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> null, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge0yxaot0qffg5ruoek|7e9a5fbe, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost/load_virtual?useTimezone=true&serverTimezone=UTC, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {password=******, user=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
abr 26, 2022 10:17:04 PM com.mchange.v2.resourcepool.BasicResourcePool
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@6462e604 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a