jsp

位置:IT落伍者 >> jsp >> 浏览文章

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


发布日期:2021年10月09日
 
JSP中调用SQL Server存储过程实例讲解

下面介绍一个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>
<%

               

上一篇:JSP+MySql的时间处理

下一篇:JSTL实现JSP应用程序快速开发