com.microsoft.sqlserver.jdbc.SQLServerException: 索引 0 超出范围。 public List<UserBean> GetPageInfo(){
List<UserBean> Users=new ArrayList<UserBean>();
UserBean ub=new UserBean();
try{
ct=new ConnDB().GetConn();
cst=ct.prepareCall("{call PageList(?,?,?,?,?,?,?)}");
cst.setString(1, "[User]");
cst.setString(2,"*");
cst.setString(3,"Id");
cst.setString(4,"");
cst.setInt(5,5);
cst.setInt(6,1);
cst.registerOutParameter(7,Types.INTEGER);
cst.execute();
int resultCount= cst.getInt(7);
rs=cst.executeQuery();
while(rs.next()){
ub.setuserId(rs.getInt(0)); //好像这句话出错
ub.setUserName(rs.getString(1));
ub.setUserPassword(rs.getString(2));
Users.add(ub);
}
return Users;
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(cst!=null)
{
cst.close();
cst=null;
}
if(ct!=null)
{
ct.close();
ct=null;
}
}catch(Exception e){
e.printStackTrace();
}
}
return null;
}
USE [stydy]
GO
/****** Object: StoredProcedure [dbo].[PageList] Script Date: 04/10/2014 10:06:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PageList]
(
@TableName varchar(50), --表名
@ReFieldsStr varchar(200) = '*', --字段名(全部字段为*)
@OrderString varchar(200), --排序字段(必须!支持多字段不用加order by)
@WhereString varchar(500) =N'', --条件语句(不用加where)
@PageSize int, --每页多少条记录
@PageIndex int = 1 , --指定当前为第几页
@TotalRecord int output --返回总记录数
)
AS
BEGIN --处理开始点和结束点
Declare @StartRecord int;
Declare @EndRecord int;
Declare @TotalCountSql nvarchar(500);
Declare @SqlString nvarchar(2000);
set @StartRecord = (@PageIndex-1)*@PageSize + 1
set @EndRecord = @StartRecord + @PageSize - 1
SET @TotalCountSql= N'select @TotalRecord = count(*) from ' + @TableName;--总记录数语句
SET @SqlString = N'(select row_number() over (order by '+ @OrderString +') as rowId,'+@ReFieldsStr+' from '+ @TableName;--查询语句
--
IF (@WhereString! = '' or @WhereString!=null)
BEGIN
SET @TotalCountSql=@TotalCountSql + ' where '+ @WhereString;
SET @SqlString =@SqlString+ ' where '+ @WhereString;
END
--第一次执行得到
--IF(@TotalRecord is null)
-- BEGIN
EXEC sp_executesql @totalCountSql,N'@TotalRecord int out',@TotalRecord output;--返回总记录数
-- END
----执行主语句
set @SqlString ='select * from ' + @SqlString + ') as t where rowId between ' + ltrim(str(@StartRecord)) + ' and ' + ltrim(str(@EndRecord));