try{
con=db.con();
CallableStatement stm=con.prepareCall("{call page(?,?,?,?,?)}");
stm.setInt(1,intPageSize);
stm.setInt(2,pag);
stm.setString(3,"news");
stm.setString(4,"news_id");
stm.registerOutParameter(5,java.sql.Types.INTEGER);
stm.executeUpdate();
stm.executeQuery();
java.math.BigInteger Pagecount=stm.getInt(5); //这句话编译时报错!!!
//stm.getObject(5);
//out.print(Pagecount);
rs=stm.getResultSet();
}
存储过程如下:
CREATE PROCEDURE page @PageSize int,
@CurrPage int,
@table char(15),
@id char(10),
@countpage int output
AS
declare @IDStr varchar(200),
@strSQL varchar(200),
@sqltr varchar(200),
@count int
set @IDStr = ''
create table ##temptable(iid int IDENTITY (1, 1) NOT NULL,mainid int NOT NULL)select @sqltr='insert ##temptable(mainid) select '+@id+' from '+@table+' order by '+@id+' desc'
exec (@sqltr)select @count=( select count(*) from ##temptable)if @count%@PageSize<>0
begin
if @count/@PageSize<0
begin
select @countpage =1
end
else
begin
select @countpage =@count/@PageSize+1
end
end
else
begin
select @countpage =@count/@PageSize
end
select @IDStr = @IDStr + ltrim(rtrim(str(MainID))) + ',' from ##temptable
where iid between ((@CurrPage-1)*@PageSize+1) and @CurrPage*@PageSize
if @IDStr <> ''
begin
select @IDStr = left(@IDStr,len(@IDStr)-1)
end
select @strSQL = 'select * from '+@table+' where '+@id+' in ('+@IDStr+') order by '+@id+' desc '
exec(@strSQL)
drop table ##temptableGO
con=db.con();
CallableStatement stm=con.prepareCall("{call page(?,?,?,?,?)}");
stm.setInt(1,intPageSize);
stm.setInt(2,pag);
stm.setString(3,"news");
stm.setString(4,"news_id");
stm.registerOutParameter(5,java.sql.Types.INTEGER);
stm.executeUpdate();
stm.executeQuery();
java.math.BigInteger Pagecount=stm.getInt(5); //这句话编译时报错!!!
//stm.getObject(5);
//out.print(Pagecount);
rs=stm.getResultSet();
}
存储过程如下:
CREATE PROCEDURE page @PageSize int,
@CurrPage int,
@table char(15),
@id char(10),
@countpage int output
AS
declare @IDStr varchar(200),
@strSQL varchar(200),
@sqltr varchar(200),
@count int
set @IDStr = ''
create table ##temptable(iid int IDENTITY (1, 1) NOT NULL,mainid int NOT NULL)select @sqltr='insert ##temptable(mainid) select '+@id+' from '+@table+' order by '+@id+' desc'
exec (@sqltr)select @count=( select count(*) from ##temptable)if @count%@PageSize<>0
begin
if @count/@PageSize<0
begin
select @countpage =1
end
else
begin
select @countpage =@count/@PageSize+1
end
end
else
begin
select @countpage =@count/@PageSize
end
select @IDStr = @IDStr + ltrim(rtrim(str(MainID))) + ',' from ##temptable
where iid between ((@CurrPage-1)*@PageSize+1) and @CurrPage*@PageSize
if @IDStr <> ''
begin
select @IDStr = left(@IDStr,len(@IDStr)-1)
end
select @strSQL = 'select * from '+@table+' where '+@id+' in ('+@IDStr+') order by '+@id+' desc '
exec(@strSQL)
drop table ##temptableGO
CREATE PROCEDURE page @PageSize int,
@CurrPage int,
@table char(15),
@id char(10),
@countpage int output
AS
declare @IDStr varchar(200),
@strSQL varchar(200),
@sqltr varchar(200),
@count int
set @IDStr = ''
create table ##temptable(iid int IDENTITY (1, 1) NOT NULL,mainid int NOT NULL)select @sqltr='insert ##temptable(mainid) select '+@id+' from '+@table+' order by '+@id+' desc'
exec (@sqltr)select @count=( select count(*) from ##temptable)
select @countpage=(@count+@PageSize-1)/@PageSize
select @IDStr = @IDStr + ltrim(rtrim(str(MainID))) + ',' from ##temptable
where iid between ((@CurrPage-1)*@PageSize+1) and @CurrPage*@PageSize
if @IDStr <> ''
begin
select @IDStr = left(@IDStr,len(@IDStr)-1)
end
select @strSQL = 'select * from '+@table+' where '+@id+' in ('+@IDStr+') order by '+@id+' desc '
exec(@strSQL)
drop table ##temptableGO
这样比较简单些