Boa tarde, tenho a seguinte classe para fazer conexão com os banco de dados.
Queria saber se isto pode ser considerado um pool de conexao:
package br.com.semente.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class FactoryConnection {
public static Connection getMysqlConnection() throws SQLException{
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Conectado ao MsSQL - Schema XXXX");
return DriverManager.getConnection("jdbc:mysql://192.168.0.12/database","xxx","xxx");
}catch (ClassNotFoundException e) {
// TODO: handle exception
throw new SQLException(e.getMessage());
}
}
public static Connection getPostGreSQLConnection() throws SQLException{
try{
Class.forName("org.postgres.Driver");
System.out.println("Conectado ao MsSQL - Schema XXXX");
return DriverManager.getConnection("jdbc:postgresql://192.168.0.12/database","xxx","xxx");
}catch (ClassNotFoundException e) {
throw new SQLException(e.getMessage());
}
}
public static Connection getMsSQLConnection() throws SQLException{
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
System.out.println("Conectado ao MsSQL - Schema XXXX");
return DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.0.12/database","xxx","xxxx");
}catch (ClassNotFoundException e) {
throw new SQLException(e.getMessage());
}
}
}
Para instanciar, faço o seguinte, diretamento no construtor do DAO:
public class EntidadeJuridicaDAO implements DAO {
PreparedStatement ps;
Connection connEntidade;
public EntidadeJuridicaDAO() throws SQLException {
this.connEntidade = FactoryConnection.getMsSQLConnection();
}
Tenho um main que insere em duas tables, ou seja, chama dois métodos insere de 2 DAO diferentes.
Como em cada DAO há um construtor com conexão, como no modelo acima. Aparece 2 mensagens na console, resultado do syso.
Agora minha dúvida é:
Isso que estou usando é um pool de conexão (singleton), ou cada chamada de um método DAO é uma conexão nova com o banco de dados?
[i]