我的错误是这样的:
org.postgresql.util.PSQLException: This connection has been closed.
at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:766)
at org.postgresql.jdbc.PgConnection.prepareStatement(PgConnection.java:1582)
at org.postgresql.jdbc.PgConnection.prepareStatement(PgConnection.java:372)
at com.ifpb.pw1.sysfood.dao.impl.UsuarioDaoBD.buscar(UsuarioDaoBD.java:61)
at com.ifpb.pw1.sysfood.managers.GerenciadorUsuario.buscaUsuario(GerenciadorUsuario.java:37)
at com.ifpb.pw1.sysfood.command.impl.Login.execute(Login.java:55)
at com.ifpb.pw1.sysfood.servlets.FrontController.processRequest(FrontController.java:26)
at com.ifpb.pw1.sysfood.servlets.FrontController.doPost(FrontController.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:764)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
但是在我的应用程序通过数据库中的查询(PostgreSQL)对用户进行身份验证之前,并没有出现任何错误。
但是当我查询以获取用户数据时,出现以下错误(如上所示)。
我的代码是这样的:
public Usuario buscar(String email) {
try {
String sql = "SELECT * FROM Usuario WHERE email = ?";
PreparedStatement stmt = conexao.prepareStatement(sql);
stmt.setString(1, email);
ResultSet resultado = stmt.executeQuery();
if(resultado.next()){
Usuario u = new Usuario(
resultado.getInt("id"),
resultado.getString("nome"),
resultado.getString("email"),
resultado.getString("profissao"),
resultado.getString("sexo"),
resultado.getBytes("fotoPerfil")
);
System.out.println("User from dao: " + u);
resultado.close();
stmt.close();
conexao.close();
return u;
}
resultado.close();
stmt.close();
conexao.close();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
我的代码有问题吗?怎么了?你能帮助我吗? 我已经做了很多研究,但是到目前为止我还找不到任何东西。