转换分离ResultSet并将其转换为CachedRowSetImpl时获取错误

时间:2012-07-24 11:33:41

标签: jdbc resultset

这个问题是由于我认为因为我使用getClob(1)而我的数据库是mysql所以CachedRowSet可能在使用mysql实现时遇到问题... :(。如果我使用getClob而不是它给出类型不匹配和当我将它转换为String并使用它时给出以下异常....

public CachedRowSet viewQuery(String query) throws SQLException, Exception {
    //query = query;
    //CachedRowSetImpl crs =
    CachedRowSet crs = new CachedRowSetImpl();

    try {
        if (connection.isClosed()) {
            setConnection();
        }
    System.out.println("Connection count 1 : " + connectionCount);

        statement = connection.createStatement();
        rs = statement.executeQuery(query);

        crs.populate(rs);
        crs = crs.createCopy();
        closeConnection();
        System.out.println("Connection count 2 : " + connectionCount);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return crs;
}       

例外:

SEVERE: Servlet.service() for servlet jsp threw exception
    java.sql.SQLException: Invalid cursor position
         at com.sun.rowset.CachedRowSetImpl.next(Unknown Source)
         at
    org.apache.jsp.eTender.Buyer.TenderBidCre_jsp._jspService(TenderBidCre_jsp.java:1460)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
         at
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
         at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at
    org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
         at
    org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
         at
    org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
         at
    org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
         at org.apache.jsp.EProc_jsp._jspService(EProc_jsp.java:532)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
         at
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
         at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
         at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
         at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
         at
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
         at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
         at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
     at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
     at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:0)

错误跟踪中有两个语句需要查看。

首先,

 org.apache.jsp.eTender.Buyer.TenderBidCre_jsp._jspService(TenderBidCre_jsp.java:1460)

第二,

org.apache.jsp.EProc_jsp._jspService(EProc_jsp.java:532)

如果您正在使用Tomcat,那么您将在/tomcat/work/Catalina/localhost/yourApp/org/apache/jsp

找到已编译的JSP

或者在您使用CachedRowSet的地方提供JSP。问题出在那里。

This可能有用。