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>
<%