Estou tentando fazer um pool de conexões, porém sem sucesso, estou recebendo o seguinte erro qdo tenta conectar no bd:
HTTP Status 500 -type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
br.com.ag7.ImpostoAg7.jdbc.acesso.Acesso.update(Acesso.java:60)
br.com.ag7.ImpostoAg7.jdbc.implementacao.CadastroCliente.incluirCliente(CadastroCliente.java:41)
br.com.ag7.ImpostoAg7.servlet.imposto.CadastrarCliente.processRequest(CadastrarCliente.java:53)
br.com.ag7.ImpostoAg7.servlet.imposto.CadastrarCliente.doPost(CadastrarCliente.java:85)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
essa é a classe acesso:
package br.com.ag7.ImpostoAg7.jdbc.acesso;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
import javax.sql.rowset.CachedRowSet;
public class Acesso {
public static final Connection getConexao() throws NamingException{
Connection c= null;
try {
Context ctx =new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/cadastro");
c = ds.getConnection();
} catch (NamingException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
return c;
}
public static final CachedRowSet query(String sql){
CachedRowSet crs = null;
try {
crs = new CachedRowSetImpl();
PreparedStatement pstm = getConexao().prepareStatement(sql);
System.out.println(sql);
crs.populate(pstm.executeQuery());
getConexao().close();
} catch (SQLException ex) {
ex.printStackTrace();
} catch (NamingException ex) {
ex.printStackTrace();
}
return crs;
}
public static final Integer update(String sql){
Integer i = null;
try {
PreparedStatement pstm = getConexao().prepareStatement(sql);
i = pstm.executeUpdate();
//pstm.execute();
getConexao().close();
} catch (SQLException ex) {
ex.printStackTrace();
} catch (NamingException ex) {
ex.printStackTrace();
}
return i;
}
}
e esse é o meu context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context >
<Resource
driverClassName="com.mysql.jdbc.Driver"
name="jdbc/cadastro"
url="jdbc:mysql://localhost:3306/cadastro?autoReconnect=true"
type="javax.sql.DataSource"
password="diogo88"
username="root"
maxActive="8"
maxIdle="4"
/>
</Context>
não conecta de jeito nenhum e parece-me correta :S
estou começando a achar q o problema está no mysql, eu preciso fazer alguma configuração nele para a minha aplicação poder conectar-se à ele?
obrigado, pessoal!
