无法从DB检索值

时间:2011-05-06 09:55:13

标签: java jsp servlets

我无法从DB中检索值。请仔细阅读代码并指导我解决问题

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)  

3 个答案:

答案 0 :(得分:3)

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

为您提供额外的帮助建议:

您的方法返回ArrayList。最好指定接口类型List(最佳实践:程序到接口而不是具体类型,以便以后可以轻松更改)。另请注意,List是通用的。您应指定列表是ReqResourceVO的列表,因此请写List<ReqResourceVO>。使用泛型意味着您的集合是类型安全的,以后不需要额外的渲染。

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

答案 1 :(得分:3)

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

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

答案 2 :(得分:0)

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