Topic: 请问,分页的时候,报这样的错误: |
Print this page |
1.请问,分页的时候,报这样的错误: | Copy to clipboard |
Posted by: kingmax2004 Posted on: 2004-12-02 16:46 请问,分页的时候,报这样的错误: 1:javax.servlet.ServletException: Result set type is TYPE_FORWARD_ONLY at org.apache.jasper.runtime.PageContextImpl.handlePageException(Unknown Source) at org.apache.jsp.index$jsp._jspService(index$jsp.java:347) at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) 2:java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY at sun.jdbc.odbc.JdbcOdbcResultSet.last(JdbcOdbcResultSet.java:2273) at org.apache.jsp.index$jsp._jspService(index$jsp.java:157) 这是不是与连接数据库的格式有关? 谢谢! |
2.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: chengbd Posted on: 2004-12-02 18:20 Result set 是“只能向前滚动”的类型,可以看看connection的连接设置吧。 建议有问题时可以把相关的代码片断贴出来,不管问题是什么,能把错误的语句先定位出来应该是“自己的事情”,这是一基本的调试基能,应该掌握。 |
3.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: kingmax2004 Posted on: 2004-12-02 18:38 那请问该如何修改呢? 数据库连接是这样的: <% Connection sConn = null; if(userBean.getDriver() == null) { userBean.setDriver("setDriver"); userBean.setURL("setURL"); userBean.setSize(20); userBean.initializePool(); } Statement stmt = null; sConn = userBean.getConnection(); stmt = sConn.createStatement(); %> |
4.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: kingmax2004 Posted on: 2004-12-02 18:38 我的代码以下: 请看那里出错?今天我弄了一天还不行,所以就请教高手了。 谢谢! <%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*,java.util.*"%> <jsp:useBean id="BTUBean" scope="page" class="myutil.MyUtil"/> <%@ include file="inc/conndb.jsp"%> <table width="760" height="50" border="0" cellpadding="0" cellspacing="1" bgcolor="#999999"> <!--DWLayoutTable--> <tr align="center" valign="middle" bgcolor="#CCCCCC"> <td width="115" height="25">ID</td> <td width="112">用?</td> <td width="107">密?</td> <td width="112">是否管理?</td> <td width="214">建???</td> <td width="55"> </td> <td width="43"> </td> </tr> <% int PageSize=3; int ShowPage=1; int RowCount=0; int PageCount=0; int temp=0; String sql="SELECT * FROM adminlog order by id desc"; ResultSet RS = stmt.executeQuery(sql); RS.last(); RowCount=RS.getRow(); temp=RowCount%PageSize; if(temp==0) { PageCount=RowCount/PageSize; }else{PageCount=RowCount/PageSize+1;} String ToPage=request.getParameter("topage"); if(ToPage==""){ToPage="1";}else{ShowPage=new Integer(ToPage).intValue(); if(ShowPage>PageCount){ShowPage=PageCount;} else if(ShowPage<=0){ShowPage=1;}} RS.absolute((ShowPage-1)*PageSize+1); int ic=1,linshi=1; linshi=ShowPage; RS.previous(); String userid,username; while(RS.next()&ic<=PageSize) { ic++; userid=RS.getString("id"); username=RS.getString("logname"); %> <tr align="center" valign="middle" bgcolor="<% if(ic%2>0) {out.print("#ffffff");}else{out.print("#e8e8e8");}%>" onMouseOver="this.style.backgroundColor='E5F0FF'" onMouseOut="this.style.backgroundColor=''"> <td height="25"><%=userid%></td> <td><%=username%></td> <td><%=RS.getString("logpasswd")%></td> <td><%=RS.getString("setadmin")%></td> <td><%=RS.getString("create_date")%></td> <td><a href="user_edit.jsp?userid=<%=userid%>&username=<%=username%>">??</a></td> <td><a href="user_del.jsp?userid=<%=userid%>" onClick="javascript:if (confirm('?定?除<%=" "+username+" "%>??')); else return false; ">?除</a></td> </tr> <% } RS.close(); stmt.close(); userBean.releaseConnection(sConn); %> </table> <table width="753" height="53" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="bottom"> 共<%=RowCount%>?,<%=ShowPage%>/<%=PageCount%>, <%linshi=ShowPage-1; if(linshi>0) {%><a href="index.jsp?ToPage=<%=linshi%>">上?</a> <%}else{%>上? <%}linshi=ShowPage+1; if(linshi<=PageCount) {%><a href="index.jsp?ToPage=<%=linshi%>">下?</a> <%}else{%>下?<%}%> </td> </tr> </table> </body> </html> |
5.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: chengbd Posted on: 2004-12-02 21:04 sConn = userBean.getConnection(); 这句是重点,用的是什么数据库,不会是access吧? |
6.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: kingmax2004 Posted on: 2004-12-03 07:12 数据库是ACCESS。 因为是我是新手,这是测试用的。请问,如果改用SQLSERVER2000,又有什么区别呢? sConn = userBean.getConnection();里的括号里好像要添加什么的,是不是啊》 请问该怎样修改呢?可以说一下原因吗?? 谢谢! |
7.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: chengbd Posted on: 2004-12-03 17:13 这是Connection的createStatement的另种API文档说明: 1。createStatement public Statement createStatement() throws SQLExceptionCreates a Statement object for sending SQL statements to the database. SQL statements without parameters are normally executed using Statement objects. If the same SQL statement is executed many times, it may be more efficient to use a PreparedStatement object. Result sets created using the returned Statement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. 2。 createStatement public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLExceptionCreates a Statement object that will generate ResultSet objects with the given type and concurrency. This method is the same as the createStatement method above, but it allows the default result set type and concurrency to be overridden. Parameters: resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE Returns: a new Statement object that will generate ResultSet objects with the given type and concurrency |
8.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: chengbd Posted on: 2004-12-03 17:22 我说错了,你有问题的是stmt = sConn.createStatement(); 不带参数时,创建的是“TYPE_FORWARD_ONLY 、CONCUR_READ_ONLY”类型的Result sets,所谓TYPE_FORWARD_ONLY 就是ResultSet RS = stmt.executeQuery(sql);中得到的RS只是“Thus, you can iterate through it only once and only from the first row to the last row.” 你可以试试这样的方法: Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2"); // rs will be scrollable, will not show changes made by others, // and will be updatable |
9.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: kingmax2004 Posted on: 2004-12-03 17:33 我修改成你所教的方法,但还是报错,类型如下: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:394) at java.lang.Integer.(Integer.java:567) at org.apache.jsp.index1$jsp._jspService(index1$jsp.java:165) at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source) at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) at org.apache.jasper.servlet.JspServlet.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) |
10.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: chengbd Posted on: 2004-12-03 17:38 我在mysql中用stmt = sConn.createStatement();使用时没遇到什么问题,想来用sql server2000也应该没什么问题的。 只是有一次帮别人调试一个access的程序,用String str=rs.getString("f1");一次后,没有其它变化,再来一次str=rs.getString("f1");,就出错了。好像修改stmt = sConn.createStatement();的参数也不行。当初调试出这个问题,也花费了不少时间。我没看你的代码,猜想可能这是一样的原因。 解决方法是ResultSet RS = stmt.executeQuery(sql);后,将rs中的数据全部先放在一个vector,list,map对象中。 其实,这也是一种标准的做法了,在ResultSet RS = stmt.executeQuery(sql);后,马上复制RS中的内容,再马上关闭RS,stmt,connection,以释放connectio资源。 具体情况还要自己来分析,调试定位出错的语句是件艰苦的事,也是基本功,既然别人能调试出来,你也应该自己能调试出来的,只是花的时间更多些。 希望你整理一下代码,把和分页相关的功能提取出来做成一个完整的web程序,再提交到页面中的附件中,以供其它人参考、调试。毕竟,如果只有部分的代码,不实际运行一下,很难确定问题的所在的。 我想这是个典型的access问题,研究一下有意义,才与你进一步交流的,那就麻烦你整理一下吧。 |
11.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: chengbd Posted on: 2004-12-03 17:43 你看,你的代码中有这样的语句:RS.previous(); 用stmt = sConn.createStatement();,再执行RS.previous();,肯定是不行的。我遇到的问题是,对于access,不仅不能执行RS.previous();,每个字段只能读取一次,只能读取一次!这是access的问题了,其它数据库好像没有这样的问题。 |
12.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: kingmax2004 Posted on: 2004-12-03 17:49 謝謝版主的提醒! 看來我還得再多看一下書了! 非常感謝大家! |
13.Re:请问,分页的时候,报这样的错误: [Re: kingmax2004] | Copy to clipboard |
Posted by: kingmax2004 Posted on: 2004-12-03 18:33 <a href="index.jsp?ToPage=<%=linshi%>">上?</a> <%}else{%>上? <%}linshi=ShowPage+1; if(linshi<=PageCount) {%><a href="index.jsp?ToPage=<%=linshi%>">下?</a> <%}else{%>下?<%}%> 这里错了,topage要区别大小写! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |