資源描述:
《java調(diào)用sqlserver存儲(chǔ)過程》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、------------------------------------------------------創(chuàng)建表CREATETABLE[BookUser]([UserID][int]IDENTITY(1,1)NOTNULL,[UserName][varchar](50)COLLATEChinese_PRC_CI_ASNOTNULL,[Title][nvarchar](50)COLLATEChinese_PRC_CI_ASNOTNULL,[Guid][uniqueidentifier]NOTNULLCONSTRAINT[DF_BookUs
2、er_Guid]DEFAULT(newid()),[BirthDate][datetime]NOTNULL,[Description][ntext]COLLATEChinese_PRC_CI_ASNOTNULL,[Photo][image]NULL,[Other][varchar](50)COLLATEChinese_PRC_CI_ASNULLCONSTRAINT[DF_BookUser_Other]DEFAULT('默認(rèn)值'),CONSTRAINT[PK_BookUser]PRIMARYKEYCLUSTERED([UserID])ON[
3、PRIMARY])ON[PRIMARY]TEXTIMAGE_ON[PRIMARY]GO----------------------------------------------------------------創(chuàng)建存儲(chǔ)過程CREATEPROCEDUREInsertUser@UserNamevarchar(50),@Titlevarchar(255),@Guiduniqueidentifier,@BirthDateDateTime,@Descriptionntext,@Photoimage,@Othernvarchar(50),@Use
4、rIDintoutputAsSetNOCOUNTONIfExists(selectUserIDfromBookUserWhereTitle=@Title)--這一句判斷數(shù)據(jù)庫某一個(gè)字段的唯一性RETURN0ELSEBeginINSERTINTOBookUser(UserName,Title,Guid,BirthDate,Description,Photo,Other)VALUES(@UserName,@Title,@Guid,@BirthDate,@Description,@Photo,@Other)SET@UserID=@@IDENTI
5、TYRETURN1EndGO------------------------------------查詢分析器中測(cè)試execInsertUser@UserName='111',@Title='測(cè)試1',@Guid='69807bfa-45a1-4f27-a21e-8b90025bff05',@BirthDate='2009-04-01',@Description='4455',@Photo=null,@Other=null,@UserID='123'--------------------------------------------頁
6、面調(diào)用<%@pagelanguage="java"import="java.util.*"pageEncoding="gbk"%><%@pageimport="java.sql.*"%><%@pageimport="java.sql.Date;"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
7、TYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
">
MyJSP'MyJsp.jsp'startingpage8、-equiv="keywords"content="keyword1,keyword2,keyword3">