Quando executo o programa o console me informa a abertura das conexões porém não consigo ver no MySql.
import java.sql.Connection;
import java.sql.SQLException;
public class TestaPool {
public static void main(String[] args) throws SQLException {
ConnectionFactory con = new ConnectionFactory();
for (int i = 1; i < 5; i++) {
con.recuperaConexao();
System.out.println(i);
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.sql.ConnectionPoolDataSource;
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.setPassword("7m75bC9@5rmr");
comboPooledDataSource.setUser("root");
comboPooledDataSource.setMaxPoolSize(5);
// comboPooledDataSource.setMaxConnectionAge(10);
this.dataSource = comboPooledDataSource;
}
Connection recuperaConexao() throws SQLException {
//System.out.println("Conexão OK");
return this.dataSource.getConnection();
}
void fechaConexao() throws SQLException {
this.dataSource.getConnection().close();
}
}