USE [hb_lottery]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[dis_insertWari]
--@ProductId_Array varChar(800),
--@ModuleId int,
@delivery varchar(50), --@usid bigint,
@postationid varchar(50), --@stid varchar(50)
@sn varchar(500)
AS
DECLARE @PointerPrev int
DECLARE @PointerCurr int
DECLARE @TSn varchar(50)
DECLARE @usid bigint,@stid varchar(50),@waid varchar(50),@dgid varchar(50)--,@status tinyint
select @usid = usid from usr_users where username = @delivery --'shoulijun'
select @stid = stid from sta_station where @postationid = @postationid --5400010240-- postationid --5480011708
--select @waid = waid,@dgid = dgid from dis_war where status = 2 and sn = @sn --3500950151246
Set @PointerPrev=1
set @PointerCurr=1
begin transaction
Set NoCount ON
--delete from ProductListSpecial where ModuleId=@ModuleId
--first
Set @PointerCurr=CharIndex('#',@sn,@PointerPrev+1)
set @TSn=SUBSTRING(@sn,@PointerPrev,@PointerCurr-@PointerPrev)
print @TSn
--Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)
select @waid = waid,@dgid = dgid from dis_war where status = 2 and sn = @TSn --3500950151246
insert into dis_warin (swid,waid,dgid,stid,sn,createtime,inputid,deliverid) values(NEWID(),@waid,@dgid,@stid
,@TSn,GETDATE(),@usid,@usid)
--second
SET @PointerPrev = @PointerCurr
while (@PointerPrev+1 < LEN(@sn))
Begin
Set @PointerCurr=CharIndex('#',@sn,@PointerPrev+1)
if(@PointerCurr>0)
Begin
set @TSn=SUBSTRING(@sn,@PointerPrev+1,@PointerCurr-@PointerPrev-1)
--Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)
select @waid = waid,@dgid = dgid from dis_war where status = 2 and sn = @TSn --3500950151246
insert into dis_warin (swid,waid,dgid,stid,sn,createtime,inputid,deliverid) values(NEWID(),@waid,@dgid,@stid,
@TSn,GETDATE(),@usid,@usid)
SET @PointerPrev = @PointerCurr
End
else
Break
End
--third
set @TSn=SUBSTRING(@sn,@PointerPrev+1,LEN(@sn)-@PointerPrev)
--Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)
select @waid = waid,@dgid = dgid from dis_war where status = 2 and sn = @TSn --3500950151246
insert into dis_warin (swid,waid,dgid,stid,sn,createtime,inputid,deliverid) values(NEWID(),@waid,@dgid,@stid,
@TSn,GETDATE(),@usid,@usid)
Set NoCount OFF
if @@error=0
begin
commit transaction
end
else
begin
rollback transaction
end
select 'ok'
java.sql.DataTruncation: Data truncation
SQL state [01004]
在jdbc插入数据时,当数据库表中某列设置的长度小于要插入的字符的实际长度时就会抛出此异常。
如:数据表中某列char [4],长度为4,插入:"string"时,字符"string"长度超过4,抛出异常。
注:插入中文字符时,在程序中用”参数.length()“统计字符时将中文识别为一个字符,但是插入数据库时,会将中文识别为两个字符,这样就造成了上面的超出长度问题。
PS:标红标粗部分在修改前为@sn,故报错。从昨天弄到今天,也从昨天郁闷到今天。不过问题解决后心情还是不错的,呵呵 ...