JSP中调用SQL Server存储过程实例讲解

ZDNet软件频道 时间:2008-09-22 作者: | 中国软件网 我要评论()
本文关键词:Server SQL JSP SQL Server
 下面介绍一个JSP调用SQL Server存储过程的实例:
 下面介绍一个JSP调用SQL Server存储过程的实例:

  创建表:

  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

  JSP代码:

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Server

SQL

JSP

SQL Server


百度大联盟认证黄金会员Copyright© 1997- CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。
中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号 京ICP备09041801号-159
京公网安备:1101082134