The SQL Server stored procedure instance is called in the JSP to explain

Source: Internet
Author: User
Tags datetime

Here is an example of a JSP calling a SQL Server stored procedure:

To create a table:

CREATE TABLE [Bookuser] (
    [UserID] [int] IDENTITY (1, 1) not NULL,
    [User Name] [varchar] (m) COLLATE chinese_prc_ci_as not NULL,
    [Title] [nvarchar] (m) COLLATE chinese_p Rc_ci_as NOT NULL,
    [Guid] [uniqueidentifier] NOT NULL CONSTRAINT [Df_bookuser_guid] DEFAULT (newid ()),
    [Birthdate] [datetime] Not NULL,
    [Description] [ntext] COLLATE chines E_prc_ci_as not NULL,
    [Photo] [image] NULL,
    [other] [varchar] (m) COLLATE Chinese_prc_ci_as NULL
CONSTRAINT [df_bookuser_other] Default (' Default value '),
    CONSTRAINT [pk_ Bookuser] PRIMARY key  CLUSTERED
    (
        [UserID ]
   )   on [PRIMARY]
in [PRIMARY] textimage_on [PRIMARY]
Go
To create the stored procedure:

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 Code:

<%@ 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" >
<body>
<%

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.