使用存储过程分页,我想取得返回值,同时使用循环取得N条记录的信息,该怎么做呢
我的过程为:
/*实现分页的存储过程*/
    CREATE PROCEDURE dbo.getUserList
       @iPageCount int OUTPUT,    /*总页数,需要返回*/
       @iPage int,                             /*-当前页号*/
       @iPageSize int                       /*-每页记录数*/
    as
    set nocount on
    begin
       /*创建临时表 */
       create table #User_New_Table
                                (
                                 UserID int Not Null,   
                                 UserName varchar(20),
                                 PassWords Varchar(16)
                                )
      /*向临时表中写入数据*/
       insert into #User_New_Table
          select * from dbo.[UserInfo_Table]
             order by UserID 
       
      /*取得记录总数 */
       declare @iRecordCount int
       set @iRecordCount = @@rowcount
     /*确定总页数*/
       IF @iRecordCount%@iPageSize=0
          SET @iPageCount=CEILING(@iRecordCount/@iPageSize)
       ELSE
          SET @iPageCount=CEILING(@iRecordCount/@iPageSize)+1
 
       /*若请求的页号大于总页数,则显示最后一页*/
       IF @iPage > @iPageCount
          SELECT @iPage = @iPageCount
      /*确定当前页的始末记录*/
       DECLARE @iStart int    /*start record*/
       DECLARE @iEnd int     /*end record*/
       SELECT @iStart = (@iPage - 1) * @iPageSize
       SELECT @iEnd = @iStart + @iPageSize + 1
     /*取当前页记录*/    
       select * from #User_New_Table where UserID>@iStart and UserID<@iEnd
       /*删除临时表*/
       DROP TABLE #User_New_Table
       /*返回记录总数*/
       RETURN @iRecordCount
    end
GO
我的JAVA程序为:
/*包名MyDB
 */
package MyDB;
import java.sql.*;
/*类名:ExeProcedure
 *专门处理SQL的存储过程
 */
public class ExeProcedure extends DBSource{
 /*构造方法
  *利用构造方法建立与数据库的连接
  */
 public ExeProcedure(){
    super();   
 }
 /*Procedure_getUserList
  *参数:iPage表示当前页号?PageSize为每页显示的条数
  */
 public  void Procedure_getUserList(int iPage,int iPageSize){         
  try{
   connect=DriverManager.getConnection(sConnstr);
      cs=connect.prepareCall("{call getUserList(?,?,?)}");
      cs.registerOutParameter(1,Types.INTEGER);
      cs.setInt(2,iPage); //当前页号 
            cs.setInt(3,iPageSize);//每页显示的总记录  
            
            if(cs.getInt(1)>0){
             /*想在此使用循环列出当前页中每条记录的信息
              *该怎么读存储过程中的   
              *select * from #User_New_Table where UserID>@iStart and UserID<@iEnd
                  呢?如果有更好的方法可以告诉我吗?急切期待!
              */
             
                  System.out.println("总页数为:"+cs.getInt(1)); 
            }
            else{
             System.out.println("没有任何记录"); 
            } 
  }catch(SQLException SQLe){
   System.err.println("发现有错误!\n"+SQLe.getMessage()); 
  }
 } 
 
 public static void main(String[] args){
    ExeProcedure E=new ExeProcedure();
     E.Procedure_getUserList(0,20);
  }  
}

 
											





