oracle executeupdate()在java servlet中没有响应

afdcj2ne  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(328)

我有两个几乎相同的代码将多个jpg文件作为blob更新到表中。神秘地。。一个有效。另一个不行。不起作用的不仅不起作用,而且oracledb也不响应apacheweb服务器
这是工作代码。它从jsp输入标记接收120多个jpg文件并发送到这个servlet。而且做得很好。

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        //connection
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "KSJ", 
        "1234");
        con.setAutoCommit(false);

        response.setContentType("text/html; charset=UTF-8");
        PrintWriter out = response.getWriter();
        int categoryID = 13;
        int productID = categoryID*10000;

        int jpgIndex = 1;
        int itemIndex = 1;
        int executeResult = 0;
        boolean isExcuted = true;

        String sql = "UPDATE PRODETAIL_T SET PDTT_MAINPIC = ?, PDTT_SMALLPIC1 = ?, PDTT_SMALLPIC2 = 
        ?, PDTT_SMALLPIC3 = ?, PDTT_SMALLPIC4 = ?, PDTT_SMALLPIC5 = ? "
                   + "WHERE PDTT_PDTID = '";
        String[] sqlArr = new String[20];
        PreparedStatement pstmt = null;

        //looping jpg files
        System.out.println("request size : "+request.getParts().size());
        for(Part jpg : request.getParts()) {
            if(isExcuted) {
                productID++;
                sqlArr[itemIndex-1] = sql;
                sqlArr[itemIndex-1] += productID + "' AND PDTT_PDTCGTID = " + categoryID;
                pstmt = con.prepareStatement(sqlArr[itemIndex-1]);
                isExcuted = false;
                jpgIndex = 1;
            }
            pstmt.setBinaryStream(jpgIndex, jpg.getInputStream(), (int)jpg.getSize());
            jpgIndex++;

            if((jpgIndex-1)%6 == 0) {
                System.out.println(sqlArr[itemIndex-1]);
              executeResult = pstmt.executeUpdate();
              pstmt.close();
              isExcuted = true;
              itemIndex++;
              if(executeResult ==0) {System.out.println("jpg upload error");}
              executeResult = 0;
            }
            if(itemIndex == 21) {
                System.out.println("commit bulk image successful for category"+categoryID);
                con.commit();
                break;
            }
        }
        con.close();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    doGet(request, response);
}

现在几乎相同的代码不起作用了

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws 
ServletException, IOException {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", 
            "KSJ", "1234");
            con.setAutoCommit(false);

            response.setContentType("text/html; charset=UTF-8");
            PreparedStatement pstmt = null;
            String sqlTemplate = "UPDATE REVIEW_T SET RVT_PICTURE1= ?, RVT_PICTURE2= ?, RVT_PICTURE3= 
            ? WHERE RVT_THUMBSUP =";
            String sql;

            int rowNum = 1;
            int jpgIndex = 1;
            int executeResult = 0;
            boolean isExcuted = true;

            for(Part jpg : request.getParts()) {
                if(isExcuted) {
                    sql = sqlTemplate + rowNum;
                    System.out.println(sql);
                    pstmt = con.prepareStatement(sql);
                    isExcuted = false;
                    jpgIndex = 1;
                }
                pstmt.setBinaryStream(jpgIndex, jpg.getInputStream(), (int)jpg.getSize());
                jpgIndex++;
                if((jpgIndex-1)%3==0) {
 works upto here>>  rowNum = rowNum + 1;
    Error here >>   executeResult = pstmt.executeUpdate();
                    if(executeResult == 1) {
                        System.out.println("One upload successful");
                    }
                    pstmt.close();
                    isExcuted = true;
                    if(executeResult ==0) {System.out.println("jpg upload error");}
                    executeResult = 0;
                }
                if(rowNum == 101) {
                    System.out.println("commit bulk image successful");
                    con.commit();
                    break;
                }
            }
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    doGet(request, response);
}

我用sysout调查了整个过程,代码挂在

executeResult = pstmt.executeUpdate();

最终eclipse/apache会抛出一些错误,表示代码仍在执行,并导致内存泄漏。我在sqldeveloper中手动插入blob列,如下所示

UPDATE RVT SET RVT_PICTURE1 = '1' , RVT_PICTURE2 = '1' ,RVT_PICTURE3 = '1'   WHERE RVT_THUMBSUP = 2;

而且没问题,所以我不认为table上有问题。有时我至少可以更新一行(但在我多次更改代码后,现在不行了。)
这是apache/eclipse在几十秒后出现的错误代码。

WARNING: The web application [ElecMarket1.0] is still processing a request 
that has yet to finish. This is very likely to create a memory leak. You can 
control the time allowed for requests to finish by using the unloadDelay 
attribute of the standard Context implementation. Stack trace of request 
processing thread:[

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题