本文章來告訴你jsp教程如何調用mssql 預存程序吧,其實調用mssql的預存程序很簡單的,下面我們先來建立表:
create table [bookuser] (
[userid] [int] identity (1, 1) not null ,
[username] [varchar] (50) collate chinese_prc_ci_as not null ,
[title] [nvarchar] (50) collate chinese_prc_ci_as not null ,
[guid] [uniqueidentifier] not null constraint [df_bookuser_guid] default (newid()),
[birthdate] [datetime] not null ,
[description] [ntext] collate chinese_prc_ci_as not null ,
[photo] [image] null ,
[other] [varchar] (50) collate chinese_prc_ci_as null
constraint [df_bookuser_other] default ('預設值'),
constraint [pk_bookuser] primary key clustered
(
[userid]
) on [primary]
) on [primary] textimage_on [primary]
go
建立預存程序:
create procedure insertuser
@username varchar(50),
@title varchar(255),
@guid uniqueidentifier,
@birthdate datetime,
@description ntext,
@photo image,
@other nvarchar(50),
@userid int output
as
set nocount on
if exists (select userid from bookuser where username = @username)
return 0
else
begin
insert into bookuser (username,title,guid,birthdate,description,photo,other)
values(@username,@title,@guid,@birthdate,@description,@photo,@other)
set @userid = @@identity
return 1
end
go