jsp分页显示问题??
我的一段程序,没加分页时是好的加了分页后提示如下错误ResultsettypeisTYPE_FORWARD_ONLY请帮忙看一下<%Stringid=request.ge...
我的一段程序,没加分页时是好的
加了分页后提示如下错误Result set type is TYPE_FORWARD_ONLY
请帮忙看一下
<%
String id=request.getParameter("articleID");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:blog","public","");
Statement stmt = con.createStatement();
String strsel = "select * from article where articleID ="+id;
ResultSet rs1 = stmt.executeQuery (strsel);
%>
<% while(rs1.next())
{
%>
<%= rs1.getString("title")%>
<%= rs1.getString("content")%>
<%
}
rs1.close();
%>
<%
String strse2 = "select * from feedback where articleID ="+id;
ResultSet rs = stmt.executeQuery (strse2);
int dipage=1;//当前页码数默认为1
String pages = request.getParameter("dipage");
if (pages==null)
{
pages="1";
}
try{
dipage =Integer.parseInt(pages);
}
catch(Exception e)
{
dipage=1;
}
int countRecord=0; //记录条数
int countPageRecord=0; //每页记录数
int countPage=0; //总页数
countPageRecord=2;
rs.last();
countRecord=rs.getRow(); //得到总页数
if ( countRecord/countPageRecord==0)
countPage = countRecord/countPageRecord;
else
countPage = countRecord/countPageRecord+1;
if ((dipage-1)*countPageRecord==0)
//rs.afterLast();
rs.beforeFirst();
else
rs.absolute((dipage-1)*countPageRecord);
%>
<%
int i=0;
int feedBackID;
while(rs.next()){
%>
<%= feedBackID = rs.getInt("feedBackID") %>
<%= rs.getString("content") %>
<%
i++;
if (i>=countPageRecord) break; //当前页显示完,则推出循环
%>
<%
}
%>
<%
if(dipage==1)
;
else
{
out.print("<a href =../blog/firstpage.jsp?dipage=1 >首页</a>  ");
out.print("<a href =../blog/firstpage.jsp?dipage="+(dipage-1)+">上一页</a>  ");
}
if (dipage==countPage)
;
else
{
out.print("<a href =../blog/firstpage.jsp?dipage="+(dipage+1)+">下一页</a>  ");
out.print("<a href =../blog/firstpage.jsp?dipage="+countPage+">末页</a> ");
}
%> 展开
加了分页后提示如下错误Result set type is TYPE_FORWARD_ONLY
请帮忙看一下
<%
String id=request.getParameter("articleID");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:blog","public","");
Statement stmt = con.createStatement();
String strsel = "select * from article where articleID ="+id;
ResultSet rs1 = stmt.executeQuery (strsel);
%>
<% while(rs1.next())
{
%>
<%= rs1.getString("title")%>
<%= rs1.getString("content")%>
<%
}
rs1.close();
%>
<%
String strse2 = "select * from feedback where articleID ="+id;
ResultSet rs = stmt.executeQuery (strse2);
int dipage=1;//当前页码数默认为1
String pages = request.getParameter("dipage");
if (pages==null)
{
pages="1";
}
try{
dipage =Integer.parseInt(pages);
}
catch(Exception e)
{
dipage=1;
}
int countRecord=0; //记录条数
int countPageRecord=0; //每页记录数
int countPage=0; //总页数
countPageRecord=2;
rs.last();
countRecord=rs.getRow(); //得到总页数
if ( countRecord/countPageRecord==0)
countPage = countRecord/countPageRecord;
else
countPage = countRecord/countPageRecord+1;
if ((dipage-1)*countPageRecord==0)
//rs.afterLast();
rs.beforeFirst();
else
rs.absolute((dipage-1)*countPageRecord);
%>
<%
int i=0;
int feedBackID;
while(rs.next()){
%>
<%= feedBackID = rs.getInt("feedBackID") %>
<%= rs.getString("content") %>
<%
i++;
if (i>=countPageRecord) break; //当前页显示完,则推出循环
%>
<%
}
%>
<%
if(dipage==1)
;
else
{
out.print("<a href =../blog/firstpage.jsp?dipage=1 >首页</a>  ");
out.print("<a href =../blog/firstpage.jsp?dipage="+(dipage-1)+">上一页</a>  ");
}
if (dipage==countPage)
;
else
{
out.print("<a href =../blog/firstpage.jsp?dipage="+(dipage+1)+">下一页</a>  ");
out.print("<a href =../blog/firstpage.jsp?dipage="+countPage+">末页</a> ");
}
%> 展开
1个回答
展开全部
Statement stmt = con.createStatement(); 打开的只是只读记录集,举个例子,执行sql语句select id,name from 表名,如果你打开记录集后先引用
rs.getString("name"), 后引用rs.getInt("id")就出错了,解决办法:
将上句Statement stmt = con.createStatement();替换成
Statement stmt =con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
就可以了
rs.getString("name"), 后引用rs.getInt("id")就出错了,解决办法:
将上句Statement stmt = con.createStatement();替换成
Statement stmt =con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
就可以了
参考资料: 实践中得出来的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询