当前位置: 技术问答>java相关
在sqlserver中Procedure有建立临时表,然后再查询这个临时表,在java执行这个Procedure就出错,怎么解决?
来源: 互联网 发布时间:2017-04-07
本文导语: 我在sqlserver中有个Procedure如下: SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO ALTER proc storage_SizeSearchBoard_RPT( @MatCategory varchar(40), @ProcessState varchar(40), @QCRankCD varchar(16), @Length ...
我在sqlserver中有个Procedure如下:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER proc storage_SizeSearchBoard_RPT(
@MatCategory varchar(40),
@ProcessState varchar(40),
@QCRankCD varchar(16),
@Length int, /* 单向最小尺寸 */
@Width int,
@Height int,
@StoreType varchar(60)
) as
create table #TempTable(
MatBoxno varchar(20),
MatGrpno varchar(20),
MatUserCD varchar(16),
MatCategoryNM varchar(40),
ProcessStateNM varchar(40),
StaUserCD varchar(16),
QCRankCD varchar(20),
WareHouse varchar(24),
Lctcd varchar(24),
InWareDate smalldatetime,
BookLstCD varchar(24),
SerialNo varchar(20),
Length int,
Width int,
Height int,
NumQty smallint,
CubeQty numeric(12,6),
Weight numeric(12,6),
TtlQty numeric(12,6),
NegativeQty numeric(12,6),
QCNote varchar(200),
Note varchar(20),
MatRate numeric(8,5),
InWareno varchar(20),
StoreType varchar(24),
ProduceArea varchar(20)
)
Declare
@pSelStr varchar(1000)
set nocount on
exec Storage_SizeSearch_BasicString @MatCategory,@ProcessState,@QCRankCD,@StoreType,'Y',@pSelStr output
if (@pSelStr='') or (@pSelStr is null)
return
insert into #TempTable(Matboxno,MatGrpno,InWareno,MatUserCD,
MatCategoryNM,ProcessStateNM,StaUserCD,QCRankCD,
WareHouse,LctCD,InWareDate,BookLstCD,SerialNo,StoreType,ProduceArea,
Length,Width,Height,NumQty,TtlQty,NegativeQty,CubeQty,Weight,QCNote) exec (@pSelStr)
update #TempTable set MatRate=Khtstone.dbo.CountMatRate(Length,Width,@Length,@Width)
select MatRate,MatUserCD,Matboxno,MatGrpno,MatCategoryNM,ProcessStateNM,QCRankCD,SerialNo,
WareHouse,LctCD,InWareDate,BookLstCD,Length,Width,Height,NumQty,TtlQty,InWareno,
NegativeQty,StoreType,ProduceArea,QCNote from #TempTable order by MatRate desc
drop table #TempTable
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
在java中调用它就出现java.sql.SQLException: given ResultSet is NULL,是不支持临时表调用?还是其他原因,同样的代码执行没有临时表的Procedure就没有问题,怎么解决啊?难道不能用临时表??
先谢谢拉
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER proc storage_SizeSearchBoard_RPT(
@MatCategory varchar(40),
@ProcessState varchar(40),
@QCRankCD varchar(16),
@Length int, /* 单向最小尺寸 */
@Width int,
@Height int,
@StoreType varchar(60)
) as
create table #TempTable(
MatBoxno varchar(20),
MatGrpno varchar(20),
MatUserCD varchar(16),
MatCategoryNM varchar(40),
ProcessStateNM varchar(40),
StaUserCD varchar(16),
QCRankCD varchar(20),
WareHouse varchar(24),
Lctcd varchar(24),
InWareDate smalldatetime,
BookLstCD varchar(24),
SerialNo varchar(20),
Length int,
Width int,
Height int,
NumQty smallint,
CubeQty numeric(12,6),
Weight numeric(12,6),
TtlQty numeric(12,6),
NegativeQty numeric(12,6),
QCNote varchar(200),
Note varchar(20),
MatRate numeric(8,5),
InWareno varchar(20),
StoreType varchar(24),
ProduceArea varchar(20)
)
Declare
@pSelStr varchar(1000)
set nocount on
exec Storage_SizeSearch_BasicString @MatCategory,@ProcessState,@QCRankCD,@StoreType,'Y',@pSelStr output
if (@pSelStr='') or (@pSelStr is null)
return
insert into #TempTable(Matboxno,MatGrpno,InWareno,MatUserCD,
MatCategoryNM,ProcessStateNM,StaUserCD,QCRankCD,
WareHouse,LctCD,InWareDate,BookLstCD,SerialNo,StoreType,ProduceArea,
Length,Width,Height,NumQty,TtlQty,NegativeQty,CubeQty,Weight,QCNote) exec (@pSelStr)
update #TempTable set MatRate=Khtstone.dbo.CountMatRate(Length,Width,@Length,@Width)
select MatRate,MatUserCD,Matboxno,MatGrpno,MatCategoryNM,ProcessStateNM,QCRankCD,SerialNo,
WareHouse,LctCD,InWareDate,BookLstCD,Length,Width,Height,NumQty,TtlQty,InWareno,
NegativeQty,StoreType,ProduceArea,QCNote from #TempTable order by MatRate desc
drop table #TempTable
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
在java中调用它就出现java.sql.SQLException: given ResultSet is NULL,是不支持临时表调用?还是其他原因,同样的代码执行没有临时表的Procedure就没有问题,怎么解决啊?难道不能用临时表??
先谢谢拉
|
临时表肯定是可以用的
只是你用临时表是返回的记录集是null
检查你取得到记录了没有,最好用while(rs.next())避免错误发生
只是你用临时表是返回的记录集是null
检查你取得到记录了没有,最好用while(rs.next())避免错误发生