J中调用SQL Server存储过程实例讲解_JSP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

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

作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0

本篇关键词:实例讲解过程存储
黑客防线网安网讯:下面介绍一个JSP调用SQL Server存储过程的实例:创建表:CREATE TABLE [BookUser] (    [UserID] [int] IDENTITY (1, 1) NOT NULL ,    [UserName] [varchar] (50) COLLATE Chinese_PRC_CI_...

下面介绍一个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代码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import = "java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<%

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-16677-1.html
网站维护教程更新时间:2012-04-07 00:44:49  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer