Opiniões: Connection Pool

2 respostas
saoj

Ficou legal isso?

http://mentawai.lohis.com.br/connfilter.jsp

Solução marota:

public C3P0ConnectionHandler(String driver, String url, String user, String pass) {
        Class klass = null;
        try {
            klass = Class.forName("com.mchange.v2.c3p0.ComboPooledDataSource");
        } catch(ClassNotFoundException e) {
            throw new IllegalStateException("C3P0 cannot be found! You probably did not put the C3P0 jars in your /WEB-INF/lib directory!");
        }
        
        try {
            Class.forName(driver);
        } catch(ClassNotFoundException e) {
            throw new IllegalStateException("Cannot find jdbc driver " + driver + "! You probably did not put your JDBC driver in your /WEB-INF/lib directory!");
        }
        
        try {
            Object cpds = klass.newInstance();
            setValue(cpds, "driverClass", driver);
            setValue(cpds, "user", user);
            setValue(cpds, "password", pass);
            setValue(cpds, "jdbcUrl", url);
            this.cpds = (DataSource) cpds;            
            
        } catch(Exception e) {
            throw new RuntimeException("Error trying to setup a C3P0 pooled data source:" + e.getMessage());
        }
    }

Fiz a inicialização por reflection, daí não preciso linkar o jar de 500K junto com o Mentawai, ou seja, tudo compila sem nenhuma dependencia externa.

Como é que a galera do C vive sem reflection?

:slight_smile: :slight_smile: :slight_smile:

2 Respostas

cv1

So pegando no peh: passe as excecoes originais pras RuntimeExceptions que vc esta jogando, ou o stack trace original (que geralmente indica qual foi o problema de verdade) vai pras picas. Mude a mensagem, tambem: talvez algo do genero “please check your classpath and web-inf/lib directory for the JDBC driver JAR” seja melhor do que “you asshole! you forgot the god damned JAR! go put it in the fucking web-inf/lib!”

Ah, e a galera do C vive muito bem sem reflection, obrigado por perguntar. Nos temos ponteiros de funcao :wink:

saoj

Tem razão !!! Boa! :?

Criado 29 de junho de 2005
Ultima resposta 30 de jun. de 2005
Respostas 2
Participantes 2