无法从数据库检索值

发布于 2024-11-05 04:15:33 字数 6064 浏览 0 评论 0原文

我无法从数据库检索该值。请仔细阅读代码并指导我解决它

public ArrayList  getReqResInfo(String id) 
{
    String methodname="createConnection";
    Connection conn  = null;
    ResultSet rs=null;
    PreparedStatement psmt;
    int req_id=0;
    String reqid=id;
    ArrayList resList=new ArrayList();
    try {
        conn = DBConnection.getJNDIConnection();
        System.out.println("getReqResInfo id=="+reqid);
        psmt= conn.prepareStatement("select * from CR_REQUEST_RESOURCE_INFO where REQUEST_ID=?");
        psmt.setInt(1,Integer.parseInt(id));
        rs= psmt.executeQuery();
        System.out.println("getReqResInfo");

        while(rs.next())
        { 
            System.out.println(rs.getString("RES_LEVEL") +" " + rs.getString("NOOF_RES") +" " + rs.getString("RES_PRIMARY_SKILL") +" " + rs.getString("RES_QUALIFICATION") +" " + rs.getString("RES_SECONDARY_SKILL") +" " + rs.getString("RES_EXP"));              
            ReqResourceVO resourceVO=new ReqResourceVO();
            resourceVO.setLevel(rs.getString("RES_LEVEL"));
            resourceVO.setNumres(rs.getString("NOOF_RES"));
            resourceVO.setPrimary(rs.getString("RES_PRIMARY_SKILL"));
            resourceVO.setQualification(rs.getString("RES_QUALIFICATION"));
            resourceVO.setSecondary(rs.getString("RES_SECONDARY_SKILL"));
            resourceVO.setYear(rs.getString("RES_EXP"));

            resList.add(resourceVO);
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    { 
        try {
            conn.close();
        } 
        catch(Exception e)
        { 
            e.printStackTrace(); 
        }
    }

    return  resList;
}

在 servlet 中,我调用此函数,如下所述

if(action.equals("view"))
{
    try
    { 
        String reqid=req.getParameter("id");
        System.out.println("id "+reqid);
        ReqProjVO reqProjVO=new ReqProjVO();
        reqProjVO.setRequestid(reqid);
        ReqResDAO reqresDAO=new ReqResDAO();
        reqProjVO=reqresDAO.getReqProjInfo(reqProjVO);
        ArrayList resVOList=reqresDAO.getReqResInfo(reqid);
        req.setAttribute("projVO", reqProjVO);
        HttpSession session = req.getSession(true);
        session.setAttribute("resVOList", resVOList);

        ReqProjDAO reqprojDAO=new ReqProjDAO();
        ArrayList projList=reqprojDAO.Project();
        req.setAttribute("projList", projList);
        System.out.println("in request resource servlet");
        RequestDispatcher rd= req.getRequestDispatcher("jsp/manager/RequestforResource.jsp");
        rd.forward(req,res);
        System.out.println("in request resource servlet");
    }
    catch(Exception e)
    { 
        e.printStackTrace();
    }
}

正在从数据库中获取值并将其打印在控制台上,但它不会转发到它将要处理的相关 JSP 页面登录 JSP 页面时,我收到这个巨大的错误。我不知道该怎么办...

java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at weblogic.utils.io.ChunkedOutputStream.writeTo(ChunkedOutputStream.java:193)
    at weblogic.servlet.internal.ResponseHeaders.writeHeaders(ResponseHeaders.java:434)
    at weblogic.servlet.internal.ServletResponseImpl.writeHeaders (ServletResponseImpl.java:1256)
    at weblogic.servlet.internal.ServletOutputStreamImpl.sendHeaders(Servlet OutputStreamImpl.java:244)
    at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:379)
    at weblogic.servlet.internal.ChunkOutput.checkForFlush(ChunkOutput.java:469)
    at weblogic.servlet.internal.ChunkOutput.write(ChunkOutput.java:304)
    at weblogic.servlet.internal.ChunkOutputWrapper.write(ChunkOutputWrapper.java:139)
    at weblogic.servlet.jsp.JspWriterImpl.write(JspWriterImpl.java:274)
    at jsp_servlet._jsp._manager.__requestforresource._jspService(__requestforresource.java:237)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run (StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet    StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:408)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:318)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:505)
    at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)
    at manager.RequestResourceServlet.doPost(RequestResourceServlet.java:181)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(Unknown Source)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)  

I am unable to retrieve the value from DB. Please go through the code and guide me in solving it

public ArrayList  getReqResInfo(String id) 
{
    String methodname="createConnection";
    Connection conn  = null;
    ResultSet rs=null;
    PreparedStatement psmt;
    int req_id=0;
    String reqid=id;
    ArrayList resList=new ArrayList();
    try {
        conn = DBConnection.getJNDIConnection();
        System.out.println("getReqResInfo id=="+reqid);
        psmt= conn.prepareStatement("select * from CR_REQUEST_RESOURCE_INFO where REQUEST_ID=?");
        psmt.setInt(1,Integer.parseInt(id));
        rs= psmt.executeQuery();
        System.out.println("getReqResInfo");

        while(rs.next())
        { 
            System.out.println(rs.getString("RES_LEVEL") +" " + rs.getString("NOOF_RES") +" " + rs.getString("RES_PRIMARY_SKILL") +" " + rs.getString("RES_QUALIFICATION") +" " + rs.getString("RES_SECONDARY_SKILL") +" " + rs.getString("RES_EXP"));              
            ReqResourceVO resourceVO=new ReqResourceVO();
            resourceVO.setLevel(rs.getString("RES_LEVEL"));
            resourceVO.setNumres(rs.getString("NOOF_RES"));
            resourceVO.setPrimary(rs.getString("RES_PRIMARY_SKILL"));
            resourceVO.setQualification(rs.getString("RES_QUALIFICATION"));
            resourceVO.setSecondary(rs.getString("RES_SECONDARY_SKILL"));
            resourceVO.setYear(rs.getString("RES_EXP"));

            resList.add(resourceVO);
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    { 
        try {
            conn.close();
        } 
        catch(Exception e)
        { 
            e.printStackTrace(); 
        }
    }

    return  resList;
}

In the servlet I am calling this function as mentioned below

if(action.equals("view"))
{
    try
    { 
        String reqid=req.getParameter("id");
        System.out.println("id "+reqid);
        ReqProjVO reqProjVO=new ReqProjVO();
        reqProjVO.setRequestid(reqid);
        ReqResDAO reqresDAO=new ReqResDAO();
        reqProjVO=reqresDAO.getReqProjInfo(reqProjVO);
        ArrayList resVOList=reqresDAO.getReqResInfo(reqid);
        req.setAttribute("projVO", reqProjVO);
        HttpSession session = req.getSession(true);
        session.setAttribute("resVOList", resVOList);

        ReqProjDAO reqprojDAO=new ReqProjDAO();
        ArrayList projList=reqprojDAO.Project();
        req.setAttribute("projList", projList);
        System.out.println("in request resource servlet");
        RequestDispatcher rd= req.getRequestDispatcher("jsp/manager/RequestforResource.jsp");
        rd.forward(req,res);
        System.out.println("in request resource servlet");
    }
    catch(Exception e)
    { 
        e.printStackTrace();
    }
}

Values are being fetched from the DB and it is printed on the console but it is not forwarding to the concerned JSP page it is going to the log in JSP page and I am getting this huge error. I dont know what to do...

java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at weblogic.utils.io.ChunkedOutputStream.writeTo(ChunkedOutputStream.java:193)
    at weblogic.servlet.internal.ResponseHeaders.writeHeaders(ResponseHeaders.java:434)
    at weblogic.servlet.internal.ServletResponseImpl.writeHeaders (ServletResponseImpl.java:1256)
    at weblogic.servlet.internal.ServletOutputStreamImpl.sendHeaders(Servlet OutputStreamImpl.java:244)
    at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:379)
    at weblogic.servlet.internal.ChunkOutput.checkForFlush(ChunkOutput.java:469)
    at weblogic.servlet.internal.ChunkOutput.write(ChunkOutput.java:304)
    at weblogic.servlet.internal.ChunkOutputWrapper.write(ChunkOutputWrapper.java:139)
    at weblogic.servlet.jsp.JspWriterImpl.write(JspWriterImpl.java:274)
    at jsp_servlet._jsp._manager.__requestforresource._jspService(__requestforresource.java:237)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run (StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet    StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:408)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:318)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:505)
    at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)
    at manager.RequestResourceServlet.doPost(RequestResourceServlet.java:181)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(Unknown Source)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷路的信 2024-11-12 04:15:33

您向我们展示的方法 (getReqResInfo()) 没有出现在堆栈跟踪中。堆栈跟踪中唯一出现在您自己的代码中的部分是manager.RequestResourceServlet.doPost(),因此问题很可能就在那里。如果您可以自己在 RequestResourceServlet.java:181 中找到问题,那就太好了!否则,请提供更多代码。

对您有额外帮助的建议:

您的方法返回一个ArrayList。最好指定接口类型,List(最佳实践:针对接口而不是具体类型进行编程,以便以后可以轻松更改它们)。另请注意,List 是通用的。您应该指定您的列表是 ReqResourceVO 列表,因此编写 List。使用泛型意味着您的集合是类型安全的,并且以后不需要额外的转换。

很高兴看到您知道如何使用 finally 在最后关闭连接,但不要忘记同时关闭结果集和语句。 :)

The method you have shown us (getReqResInfo()) does not appear in the stack trace. The only part of the stack trace that appears to be in your own code is manager.RequestResourceServlet.doPost(), so it's likely the problem lies there. If you can find the problem yourself in RequestResourceServlet.java:181 then great! Otherwise, provide more code.

Extra helpful advice for you:

Your method returns an ArrayList. Better to specify the interface type, List instead (best practise: program to interfaces rather than concrete types so they can easily be changed later). Also, note that Lists are generic. You should specify that your list is a list of ReqResourceVO, so write List<ReqResourceVO>. Using generics means your collection is type-safe and you don't need extra casting later.

It's good to see that you know how to use finally to close the connection at the end, but don't forget to also close the resultset and the statement. :)

淡淡的优雅 2024-11-12 04:15:33

当客户端发出请求,并且在收到完整响应之前,发生以下任一情况时会发生此异常:

  1. 客户端的浏览器已关闭。
  2. 客户端的连接已断开。
  3. 客户按下停止按钮。

更多信息

This exception occurs when a client made a request, and before receiving the full response, either of the following happened:

  1. client's browser has been closed.
  2. client's connection has been disconnected.
  3. client presses the stop button.

More info.

甜妞爱困 2024-11-12 04:15:33

在req.getRequestDispatcher中调用我的兴趣点到了jsp页面的路径。您是否应该尝试以斜线 / 开头,就像我发现的许多示例一样?所以它开始 /jsp/ 而不是普通的 jsp/

In req.getRequestDispatcher call my interest points to the path of the jsp page. Should you try starting it with a slash / like many examples I have found are starting? So it starts /jsp/ instead of plain jsp/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文