本站首页
管理页面
写新日志
退出
[QQ:172832876] [MSN:lanlanq@hotmail.com]
麒麟在天欢迎您
.:
日期
«
November 2025
»
日
一
二
三
四
五
六
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
.:
我的分类
首页(64)
J2EE(27)
架构设计(1)
休闲时刻(8)
C++/C#(DotNet)(9)
项目管理(8)
Lotus Notes(6)
.:
最新日志
继承ConfigurationSecti
做正确的事,正确的做事[续1]
c# 数据库连接管理类
做正确的事,正确的做事
摄像头控件(C#)选像,拍照,保存不同数
从网上找的 content-type 类
引发类型为“System.Windows
java.security 类 Acc
instanceof
计算日期
.:
显示信息
blog名称:
日志总数:64
评论数量:34
留言数量:3
访问次数:344990
建立时间:2006年3月10日
.:
留言板
签写新留言
我也向往美好的生活
.:
链接
奕友软件
宋传芳的Blog
公告
在属于自己的一片天空中,敲打着键盘,记录下自己感兴趣和认为自己因该回忆的碎片,可能是财富,也可能是不足,过后你会发现你的进步,这就足够。
[J2EE]
hibernate2的环境配置和使用,及其配置中应该注意的事项(4)
原创空间
,
软件技术
luckystar
发表于 2006/3/10 9:19:31
* 与setUp方法相对应,JUnit TestCase执行完毕时,会自动调用tearDown方法 * 一般用于资源释放 * 此例中,用于关闭在setUp方法中打开的Hibernate Session */ protected void tearDown() throws Exception { try { if (session != null) { session.close(); } } catch (HibernateException ex) { ex.printStackTrace(); } } /** * 对象持久化(Insert)测试方法 * JUnit中,以”test”作为前缀的方法为测试方法,将被JUnit自动添加 * 到测试计划中运行 */ public void testInsert() { try { TblCdwlAdmin tblcdwladmin = new TblCdwlAdmin(); tblcdwladmin.setAdId(DataTools.getSignID()); tblcdwladmin.setAdPassword("666666"); tblcdwladmin.setAdRegdate(DateTools.getNowDate()); tblcdwladmin.setAdUsername("admin"); if (session != null) { //执行一个事务 net.sf.hibernate.Transaction tas = session.beginTransaction(); try { session.save(tblcdwladmin); session.flush(); //提交一个事务 tas.commit(); } catch (Exception ex) { //事务回滚 tas.rollback(); } } } catch (HibernateException ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } } /** * 对象读取(Select)测试 * 请保证运行之前数据库中已经存在ID='ID'的记录 */ public Object testSelect(String id) { String sql = "from TblCdwlAdmin where AD_Id='" + id + "'"; Object ob = null; try { List userList = session.find(sql); if (userList.size() > 0) { ob = userList.get(0); } } catch (HibernateException ex) { ex.printStackTrace(); } return ob; } //thank you very much ------ add by gzh 20050430 hahahaha public static void main(String[] args) { try { /** HibernateTest hib = new HibernateTest(); hib.setUp(); hib.testInsert(); hib.tearDown(); */ HibernateTest hib = new HibernateTest(); hib.setUp(); TblCdwlAdmin tbl = (TblCdwlAdmin) hib.testSelect("dcrOwjeiH"); System.out.println(tbl.getAdUsername()); } catch (Exception ex) { ex.printStackTrace(); } } } 运行main方法,数据写入读取成功。oK,,Hibernate配置成功,你可以使用了!!
阅读全文(2045)
|
回复(0)
|
编辑
|
精华
发表评论:
昵称:
密码:
主页:
标题:
验证码:
(不区分大小写,请仔细填写,输错需重写评论内容!)
站点首页
|
联系我们
|
博客注册
|
博客登陆
Sponsored By
W3CHINA
W3CHINA Blog 0.8 Processed in 0.395 second(s), page refreshed 144800744 times.
《全国人大常委会关于维护互联网安全的决定》
《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号