<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0063)http://www.blogjava.net/amigoxie/archive/2007/08/15/136828.html -->
<HTML><HEAD id=Head><TITLE>Hibernate3.x调用存储过程 - 阿蜜果 - BlogJava</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META id=metaKeywords content=Hibernate3.x调用存储过程 name=keywords><LINK id=MainCss
href="Hibernate3_x调用存储过程 - 阿蜜果 - BlogJava.files/style.css" type=text/css
rel=stylesheet><LINK id=RSSLink title=RSS
href="http://www.blogjava.net/amigoxie/rss.aspx" type=application/rss+xml
rel=alternate>
<META content="MSHTML 6.00.2900.3268" name=GENERATOR></HEAD>
<BODY>
<FORM id=Form1 name=Form1 onsubmit="javascript:return WebForm_OnSubmit();"
action=136828.html method=post>
<DIV><INPUT id=__EVENTTARGET type=hidden name=__EVENTTARGET> <INPUT
id=__EVENTARGUMENT type=hidden name=__EVENTARGUMENT> <INPUT
id=" __VIEWSTATE" type=hidden name=__VIEWSTATE> </DIV>
<SCRIPT type=text/javascript>
<!--
var theForm = document.forms['Form1'];
if (!theForm) {
theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</SCRIPT>
<SCRIPT src="Hibernate3_x调用存储过程 - 阿蜜果 - BlogJava.files/WebResource.axd"
type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript>
function ctlent(evt,id)
{
if(evt.ctrlKey && evt.keyCode == 13)
{
try
{
TempSave(id);
}
catch(ex)
{
}
finally
{
__doPostBack('AjaxHolder$PostComment$btnSubmit','')
}
}
}</SCRIPT>
<SCRIPT language=JavaScript>function SetReplyAuhor(author){document.getElementById('AjaxHolder_PostComment_tbComment').value+="@"+author+"\n";document.getElementById('AjaxHolder_PostComment_tbComment').focus();return false}</SCRIPT>
<SCRIPT src="Hibernate3_x调用存储过程 - 阿蜜果 - BlogJava.files/ScriptResource.axd"
type=text/javascript></SCRIPT>
<SCRIPT
src="E:\南凌科技\java相关文档\Hibernate\Hibernate3_x调用存储过程 - 阿蜜果 - BlogJava.files\ScriptResource(1).axd"
type=text/javascript></SCRIPT>
<SCRIPT
src="E:\南凌科技\java相关文档\Hibernate\Hibernate3_x调用存储过程 - 阿蜜果 - BlogJava.files\ScriptResource(2).axd"
type=text/javascript></SCRIPT>
<SCRIPT type=text/javascript>
<!--
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
// -->
</SCRIPT>
<!--done-->
<DIV id=centerbody align=center>
<DIV id=header><!--done-->
<DIV class=header>
<DIV class=headerText><A class=headermaintitle id=Header1_HeaderTitle
href="http://www.blogjava.net/amigoxie/">阿蜜果</A>
<DIV
id=headersubtitle> 不骄,不矜,勤工,好学,才是好女子<BR></DIV></DIV></DIV></DIV>
<DIV id=mytopmenu>
<DIV id=mylinks><!--done--><A class=menu id=MyLinks1_HomeLink
href="http://www.blogjava.net/">BlogJava</A> <A class=menu
id=MyLinks1_MyHomeLink
href="http://www.blogjava.net/amigoxie/">首页</A> <A class=menu
id=MyLinks1_NewPostLink
href="http://www.blogjava.net/amigoxie/admin/EditPosts.aspx?opt=1">新随笔</A>
<A class=menu id=MyLinks1_NewArticleLink
href="http://www.blogjava.net/EnterMyBlog.aspx?NewArticle=1">新文章</A>
<A class=menu id=MyLinks1_ContactLink accessKey=9
href="http://www.blogjava.net/amigoxie/contact.aspx?id=1">联系</A>
<A class=menu id=MyLinks1_Syndication
href="http://www.blogjava.net/amigoxie/rss">聚合</A><A id=MyLinks1_XMLLink
href="http://www.blogjava.net/amigoxie/rss"><IMG
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px"
src="Hibernate3_x调用存储过程 - 阿蜜果 - BlogJava.files/xml.gif"></A>
<A class=menu id=MyLinks1_Admin
href="http://www.blogjava.net/amigoxie/admin/EditPosts.aspx">管理</A> </DIV><!--done-->
<DIV class=blogStats>posts - 187, comments - 762, trackbacks - 0
</DIV></DIV>
<DIV id=main>
<DIV id=centercontent><!--done-->
<DIV class=post>
<DIV class=postTitle><A class=postTitle2 id=viewpost1_TitleUrl
href="http://www.blogjava.net/amigoxie/archive/2007/08/15/136828.html">Hibernate3.x调用存储过程</A>
</DIV>
<P>原文出处:<STRONG><SPAN>http://tech.it168.com/j/d/<ST1:CHSDATE Year="2007"
Month="5" Day="14" IsLunarDate="False" IsROCDate="False"
w:st="on">2007-05-14</ST1:CHSDATE>/200705141007843.shtml</SPAN></STRONG><BR>说明:该文不得转载</P>
<P><STRONG><SPAN>摘要:</SPAN></STRONG><SPAN>本文以详尽的实例展示了<SPAN>hibernate3.x</SPAN>中调用存储过程各步骤,从建立测试表、存储过程的建立、工程的建立以及类的编写和测试一步一步引导用户学习<SPAN>hibernate3.x</SPAN>中调用存储过程的方法<SPAN>.</SPAN></SPAN></P>
<P><SPAN>如果底层数据库(<SPAN>eg.
Oracle</SPAN>、<SPAN>mysql</SPAN>、<SPAN>sqlserver</SPAN>)等支持存储过程,可通过存储过程执行批量删除、更新等操作。本文以实例说明在<SPAN>hibernate3.x</SPAN>中如何调用存储过程。</SPAN></P>
<P><SPAN> </SPAN><SPAN>说明:本例<SPAN>hibernate</SPAN>所用版本为<SPAN>3.0</SPAN>,<SPAN>mysql</SPAN>所用版本为<SPAN>5.0</SPAN>,所用数据库驱动为<SPAN>mysql-connector-java-<ST1:CHSDATE
Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False"
w:st="on">5.0.4</ST1:CHSDATE>-bin.jar</SPAN>。</SPAN></P>
<P><STRONG><SPAN><SPAN>一.<SPAN>
</SPAN></SPAN></SPAN></STRONG><STRONG><SPAN>建表与初始化数据</SPAN></STRONG></P>
<P><SPAN> </SPAN><SPAN>在<SPAN>mysql</SPAN>的<SPAN>test</SPAN>数据库中建立一张新表:<SPAN>tbl_user,</SPAN>建表语句如下:</SPAN></P>
<P><SPAN> DROP TABLE IF EXISTS `user`;</SPAN></P>
<P><SPAN>CREATE TABLE `tbl_user` (</SPAN></P>
<P><SPAN> `userid` varchar(50) NOT NULL,</SPAN></P>
<P><SPAN> `name` varchar(50) default '',</SPAN></P>
<P><SPAN> `blog` varchar(50) default '',</SPAN></P>
<P><SPAN> PRIMARY KEY (`userid`)</SPAN></P>
<P><SPAN>) ENGINE=InnoDB DEFAULT CHARSET=gb2312;</SPAN></P>
<P> </P>
<P><SPAN> </SPAN><SPAN>建表成功后,在该表中插入如下<SPAN>4</SPAN>条初始数据,对应的<SPAN>sql</SPAN>语句如下:</SPAN></P>
<P><SPAN>INSERT INTO `tbl_user` (`userid`,`name`,`blog`) VALUES ('ant',
'</SPAN><SPAN>蚂蚁<SPAN>', 'http://www.blogjava.net/qixiangnj');</SPAN></SPAN></P>
<P><SPAN>INSERT INTO `tbl_user` (`userid`,`name`,`blog`) VALUES ('beansoft',
'bean', 'http://www.blogjava.net/beansoft');</SPAN></P>
<P><SPAN>INSERT INTO `tbl_user` (`userid`,`name`,`blog`) VALUES ('sterning',
'</SPAN><SPAN>似水流年<SPAN>',
'http://www.blogjava.net/sterning');</SPAN></SPAN></P>
<P><SPAN>INSERT INTO `tbl_user` (`userid`,`name`,`blog`) VALUES ('tom', 'tom' ,
'http://www.blogjava.net/tom');</SPAN></P>
<P> </P>
<P><STRONG><SPAN><SPAN>二.<SPAN>
</SPAN></SPAN></SPAN></STRONG><STRONG><SPAN>建立存储过程</SPAN></STRONG></P>
<P><SPAN>为测试<SPAN>hibernate3.x</SPAN>中存储过程的调用,我们在<SPAN>user</SPAN>表中建立<SPAN>getUserList</SPAN>、<SPAN>createUser</SPAN>、<SPAN>updateUser</SPAN>和<SPAN>deleteUser</SPAN>这四�
评论0