Javafree
 Forum   Topics   Author   Post 
Banco de Dados - JDBC / SQL The server encountered an internal error that prevented it from fulfilling this request. fg_bispo Caros, boa noite, Estou precisando de uma ajuda, estou fazendo um trabalho da faculdade, porém me deparei com um erro ao tentar recuperar o resultado de um select. Vocês poderiam me ajudar por favor? Está retornando o seguinte erro: [code] Nov 10, 2014 11:52:55 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [servlet.ControllerServlet] in context with path [/Projeto-BancoFGB] threw exception [A lógica de negócios causou uma exceção] with root cause java.lang.NullPointerException at data.ClienteDAO.consultarCliente(ClienteDAO.java:99) at logica.Consultar.executa(Consultar.java:16) at servlet.ControllerServlet.doPost(ControllerServlet.java:29) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) Nov 11, 2014 12:00:18 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/Projeto-BancoFGB] has started Nov 11, 2014 12:00:18 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc SEVERE: The web application [/Projeto-BancoFGB] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Nov 11, 2014 12:00:18 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/Projeto-BancoFGB] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Nov 11, 2014 12:00:19 AM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/Projeto-BancoFGB] is completed [/code] Classe DAO [code] public Cliente consultarCliente(String cpf) throws ClassNotFoundException, SQLException{ Cliente cli = null; Connection connection = new ConnectionFactory().getConnection(); String query = "SELECT * FROM bancofgb.cliente where cpf = ?"; PreparedStatement ps = connection.prepareStatement(query); ps.setString(1, cpf); ResultSet rs = ps.executeQuery(); if(rs.next()){ cli.setCpf(rs.getString(1)); cli.setNome(rs.getString(2)); cli.setEndereco(rs.getString(3)); cli.setTelefone(rs.getString(4)); cli.setRenda(rs.getDouble(5)); cli.setLimite(rs.getDouble(6)); cli.setStatus(rs.getInt(7)); ps.close(); } return cli; } [/code] Classe Consultar [code] public class Consultar implements Logica { public String executa(HttpServletRequest req, HttpServletResponse res) throws Exception { String cpf = req.getParameter("cpf"); ClienteDAO cDAO = new ClienteDAO(); Cliente cliente = cDAO.consultarCliente(cpf); if(cliente != null){ req.setAttribute("cpf", cliente.getCpf()); req.setAttribute("nome", cliente.getNome()); req.setAttribute("endereco", cliente.getEndereco()); req.setAttribute("telefone", cliente.getTelefone()); req.setAttribute("renda", cliente.getRenda()); req.setAttribute("limite", cliente.getLimite()); req.setAttribute("status", cliente.getStatus()); return "cliente-consultado.jsp"; } else{ return "consultar-cliente.jsp"; } } } [/code]
Goto page 1