熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JSP中調用SQL Server存儲過程實例講解

2022-06-13   來源: JSP教程 

  下面介紹一個JSP調用SQL Server存儲過程的實例

  創建表

  CREATE TABLE [BookUser] (
    [UserID] [int] IDENTITY ( ) NOT NULL
    [UserName] [varchar] () COLLATE Chinese_PRC_CI_AS NOT NULL
    [Title] [nvarchar] () 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] () 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()
@Title varchar()
@Guid  uniqueidentifier
@BirthDate DateTime
@Description ntext
@Photo image
@Other nvarchar()
@UserID int output
As
Set NOCOUNT ON
If Exists (select UserID from BookUser Where UserName = @UserName)
RETURN
ELSE
Begin
INSERT INTO BookUser (UserNameTitleGuidBirthDateDescriptionPhotoOther)
VALUES(@UserName@Title@Guid@BirthDate@Description@Photo@Other)
SET @UserID = @@IDENTITY
RETURN
End
GO
JSP代碼

  <%@ page language="java" contentType="text/html; charset=UTF" pageEncoding="UTF"%>
<%@ page import = "javasql*"%>
<!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN"
"
<html xmlns="
<head>
</head>
<body>
<%
 


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20146.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.