存储过程分页,如何取到记录集?
我附上我的存储过程:
CREATE PROCEDURE infopagelist
@currentpage int,@keyword varchar(100)
as
SET NOCOUNT ON
Declare @p1 int,@rowcount int,@pagesize int,@sqlstr varchar(1000)
set @pagesize=40
set @sqlstr= 'select id,title from T_info '
if @keyword!= ' ' begin
set @sqlstr=@sqlstr+ ' where title like ' '% '+@keyword+ '% ' ' '
end
set @sqlstr=@sqlstr+ ' order by id desc '
exec sp_cursoropen @p1 output,@sqlstr,@scrollopt=1,@ccopt=1
--select ceiling(1.0*@rowcount/@pagesize) as totalpage
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @p1,16,@currentpage,@pagesize
exec sp_cursorclose @p1
set nocount off
GO
下面是的我程序,我无法运行了,那位好心人帮我看看
<%@ page contentType= "text/html;charset=GBK " %> <%@ page import= "java.sql.* " %> <%@ page import= "comic.count " %> <jsp:useBean id= "count " scope= "page " class= "comic.count " /> <%
ResultSet revalue=null;
Connection conn;
Statement stmt;
String proname= "infopagelist ",par= "1,性 ";
String call_pro_str= "{call "+proname+ "( ";
String[] pars=par.split( ", ");
for(int i=0;i <pars.length;i++)
{call_pro_str=call_pro_str+ "?, ";}
call_pro_str=call_pro_str.substring(0,call_pro_str.length()-1);
call_pro_str=call_pro_str+ ")} ";
conn = DriverManager.getConnection(url, user, pass);
CallableStatement call_pro=conn.prepareCall(call_pro_str);//创建对象
call_pro.setString(1,pars[0]);
call_pro.setString(2,pars[1]);
call_pro.executeQuery();
revalue=call_pro.getResultSet();
call_pro.getMoreResults();
revalue=call_pro.executeQuery();
call_pro.close();
conn.close();
while(revalue.next()){
out.print(revalue.getString( "id ")+ " <br> ");
}
%>
或者那位好心人给我源代码(存储过程+jsp程序),我自已研究也可以
------解决方案--------------------给出错误提示.好便于分析错误.
------解决方案--------------------call_pro.close();
conn.close();
要放在 while 循环下面。ResultSet 中的数据,在循环的时候才开始从数据库中读。