光の境
光の代碼學(xué)習(xí)基地
BlogJava
首頁(yè)
新隨筆
聯(lián)系
聚合
管理
隨筆檔案
2007年9月 (2)
2007年7月 (1)
2007年6月 (1)
2007年4月 (4)
文章檔案
2007年7月 (1)
2007年4月 (1)
最新隨筆
1.?struts2可以直接在頁(yè)面中調(diào)用action
2.?struts2中action實(shí)現(xiàn)Preparable接口的利弊
3.?IT人員健康工作表
4.?javascript總為這種問(wèn)題費(fèi)心力,索性貼在這吧
5.?spring學(xué)習(xí)記錄
6.?smartupload and JExcel
7.?prototype api 中文版
8.?iBatis使用記錄
最新評(píng)論
1.?re: struts2中action實(shí)現(xiàn)Preparable接口的利弊
這個(gè)接口確實(shí)不大好,好處是在重載方法prepare方法里可以做初始化
--路人甲
2.?re: prototype api 中文版
79cha.com 頂了
--renren
3.?re: prototype api 中文版
好!很好!非常好!
--whsx_01
4.?re: prototype api 中文版
ding !!!!!
--js
5.?re: struts2中action實(shí)現(xiàn)Preparable接口的利弊
關(guān)注中 樓主把學(xué)習(xí)struts2的經(jīng)驗(yàn)告訴下吧 最近一直研究這個(gè)
聯(lián)系方式 wanganyuaa@163.com
qq 86322989
不勝感激
--way
iBatis使用記錄
Posted on 2007-04-07 16:55
它山の石
閱讀(577)
評(píng)論(4)
編輯
收藏
SqlMapConfig.xml
1
<?
xml version="1.0" encoding="UTF-8"
?>
2
<!
DOCTYPE sqlMapConfig
3
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
4
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd"
>
5
<
sqlMapConfig
>
6
<
properties
resource
="com/sigon/ibatis/SqlMapConfig.properties"
/>
7
<
settings
cacheModelsEnabled
="true"
enhancementEnabled
="true"
lazyLoadingEnabled
="true"
errorTracingEnabled
="true"
maxRequests
="32"
maxSessions
="10"
maxTransactions
="5"
useStatementNamespaces
="false"
/>
8
9
<
transactionManager
type
="JDBC"
commitRequired
="false"
>
10
<
dataSource
type
="SIMPLE"
>
11
<
property
name
="JDBC.Driver"
value
="${driver}"
/>
12
<
property
name
="JDBC.ConnectionURL"
value
="${url}"
/>
13
<
property
name
="JDBC.Username"
value
="${username}"
/>
14
<
property
name
="JDBC.Password"
value
="${password}"
/>
15
<
property
name
="Pool.MaximumActiveConnections"
value
="10"
/>
16
<
property
name
="Pool.MaximumIdleConnections"
value
="5"
/>
17
<
property
name
="Pool.MaximumWait"
value
="60000"
/>
18
</
dataSource
>
19
</
transactionManager
>
20
<
sqlMap
resource
="com/sigon/ibatis/maps/User.xml"
/>
21
</
sqlMapConfig
>
22
user.xml
1
<?
xml version="1.0" encoding="UTF-8"
?>
2
<!
DOCTYPE sqlMap
3
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
4
"http://ibatis.apache.org/dtd/sql-map-2.dtd"
>
5
<
sqlMap
namespace
="User"
>
6
7
<
typeAlias
alias
="user"
type
="com.sigon.ibatis.User"
/>
8
<
select
id
="getUser"
parameterClass
="java.lang.String"
resultClass
="user"
>
9
<![CDATA[
10
select
11
name,
12
sex
13
from t_user
14
where name = #name#
15
]]>
16
</
select
>
17
18
<
select
id
="getAllUser"
resultClass
="user"
>
19
<![CDATA[
20
select
21
id,
22
name,
23
sex
24
from t_user
25
]]>
26
</
select
>
27
28
<
update
id
="updateUser"
parameterClass
="user"
>
29
<![CDATA[
30
UPDATE t_user SET name=#name#, sex=#sex# WHERE id = #id#
]]>
31
</
update
>
32
33
<
insert
id
="insertUser"
parameterClass
="user"
>
INSERT INTO t_user ( name, sex) VALUES ( #name#, #sex# )
</
insert
>
34
35
<
delete
id
="deleteUser"
parameterClass
="java.lang.String"
>
delete from t_user where id=#value#
</
delete
>
36
<img src="http://www.blogjava.n
App.java
1
package
com.sigon.ibatis;
2
3
import
java.sql.SQLException;
4
import
java.util.List;
5
6
import
com.sigon.ibatis.User;
7
import
com.ibatis.sqlmap.client.SqlMapClientBuilder;
8
9
/** */
/**
10
*
11
*
@author
zhupan
12
*/
13
public
class
App
{
14
15
public
static
void
update()
{
16
//
首先初始化iBatis獲得一個(gè)SqlMapClient對(duì)象
17
String resource
=
"
com/sigon/ibatis/maps/SqlMapConfig.xml
"
;
18
com.ibatis.sqlmap.client.SqlMapClient sqlMap
=
null
;
19
try
{
20
java.io.Reader reader
=
com.ibatis.common.resources.Resources
21
.getResourceAsReader(resource);
22
sqlMap
=
SqlMapClientBuilder.buildSqlMapClient(reader);
23
}
catch
(Exception e)
{
24
e.printStackTrace();
25
}
26
//
sqlMap系統(tǒng)初始化完畢,開(kāi)始執(zhí)行update操作
27
try
{
28
sqlMap.startTransaction();
29
User user
=
new
User();
30
user.setId(
new
Integer(
1
));
31
user.setName(
"
zhupan
"
);
32
user.setSex(
new
Integer(
1
));
33
sqlMap.update(
"
updateUser
"
, user);
34
sqlMap.commitTransaction();
35
}
catch
(SQLException e)
{
36
System.out.println(e.getMessage());
37
}
finally
{
38
try
{
39
sqlMap.endTransaction();
40
}
catch
(SQLException e)
{
41
e.printStackTrace();
42
}
43
}
44
}
45
public
static
List getUser()
{
46
//
首先初始化iBatis獲得一個(gè)SqlMapClient對(duì)象
47
String resource
=
"
com/sigon/ibatis/maps/SqlMapConfig.xml
"
;
48
com.ibatis.sqlmap.client.SqlMapClient sqlMap
=
null
;
49
List list
=
null
;
50
try
{
51
java.io.Reader reader
=
com.ibatis.common.resources.Resources
52
.getResourceAsReader(resource);
53
sqlMap
=
SqlMapClientBuilder.buildSqlMapClient(reader);
54
}
catch
(Exception e)
{
55
e.printStackTrace();
56
}
57
//
sqlMap系統(tǒng)初始化完畢,開(kāi)始執(zhí)行g(shù)etAllUser操作
58
try
{
59
sqlMap.startTransaction();
60
list
=
sqlMap.queryForList(
"
getAllUser
"
,
null
);
61
sqlMap.commitTransaction();
62
}
catch
(SQLException e)
{
63
System.out.println(e.getMessage());
64
}
finally
{
65
try
{
66
sqlMap.endTransaction();
67
}
catch
(SQLException e)
{
68
e.printStackTrace();
69
}
70
}
71
return
list;
72
}
73
public
static
void
main(String[] args)
{
74
//
update();
75
List list
=
getUser();
76
User u
=
null
;
77
for
(
int
i
=
0
;i
<
list.size(); i
++
)
78
{
79
u
=
(User)list.get(i);
80
System.out.println(u.getId()
+
"
"
+
u.getName()
+
"
"
+
u.getSex());
81
}
82
}
83
}
Feedback
#
re: iBatis使用記錄
回復(fù)
更多評(píng)論
2007-04-16 11:24 by
echo
System.out.println(u.getId()+" "+u.getName()+" "+u.getSex()); 請(qǐng)問(wèn)為什么我運(yùn)行結(jié)果什么都沒(méi)有呢?不知道原因啊 !請(qǐng)教
#
re: iBatis使用記錄
回復(fù)
更多評(píng)論
2007-04-18 22:21 by
ryan
不需要在每個(gè)方法都初始化iBatis獲得一個(gè)SqlMapClient對(duì)象吧
#
re: iBatis使用記錄
回復(fù)
更多評(píng)論
2007-04-27 19:30 by
它山の石
@echo
我猜你數(shù)據(jù)庫(kù)的表中沒(méi)有記錄吧
#
re: iBatis使用記錄
回復(fù)
更多評(píng)論
2007-04-27 19:31 by
它山の石
@ryan
呵呵這位大俠說(shuō)的對(duì),確實(shí)不用每個(gè)方法都初始化,這里只是做為試用而已,呵呵
新用戶(hù)注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶(hù)
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
公告
常用鏈接
我的隨筆
我的評(píng)論
我的參與
最新評(píng)論
java
eamoi
oksonic
評(píng)論排行榜
1.?iBatis使用記錄(4)
2.?prototype api 中文版(3)
3.?struts2中action實(shí)現(xiàn)Preparable接口的利弊(2)
4.?IT人員健康工作表(0)
5.?javascript總為這種問(wèn)題費(fèi)心力,索性貼在這吧(0)
閱讀排行榜
1.?struts2中action實(shí)現(xiàn)Preparable接口的利弊(6662)
2.?prototype api 中文版(2445)
3.?struts2可以直接在頁(yè)面中調(diào)用action(858)
4.?smartupload and JExcel(718)
5.?iBatis使用記錄(577)
posts - 8, comments - 9, trackbacks - 0, articles - 2
Copyright © 它山の石
主站蜘蛛池模板:
一级看片免费视频囗交
|
亚洲人精品亚洲人成在线
|
亚洲av无码一区二区三区网站
|
亚洲av永久无码精品秋霞电影影院
|
亚洲日本在线观看
|
亚洲Av无码一区二区二三区
|
亚洲av色香蕉一区二区三区
|
成人特级毛片69免费观看
|
免费国产成人α片
|
国产在线观看麻豆91精品免费
|
午夜男人一级毛片免费
|
亚洲国产精品成人久久蜜臀
|
久久久久久a亚洲欧洲aⅴ
|
亚洲毛片一级带毛片基地
|
国产美女被遭强高潮免费网站
|
免费一区二区三区
|
h片在线免费观看
|
最近国语视频在线观看免费播放
|
无码国产精品一区二区免费16
|
97在线观免费视频观看
|
免费在线观看黄网站
|
亚洲天堂久久精品
|
亚洲乱色熟女一区二区三区蜜臀
|
亚洲一区精彩视频
|
日本一区二区在线免费观看
|
国产精品久久久久久亚洲影视
|
亚洲日韩一中文字暮
|
国产精品青草视频免费播放
|
在线视频免费观看爽爽爽
|
亚洲AV伊人久久青青草原
|
久久久久亚洲精品无码蜜桃
|
国产精品亚洲精品久久精品
|
亚洲精品免费在线
|
免费观看国产网址你懂的
|
日本最新免费不卡二区在线
|
成全视成人免费观看在线看
|
97国产免费全部免费观看
|
内射无码专区久久亚洲
|
亚洲国产精品VA在线看黑人
|
亚洲国产精品精华液
|
日韩免费电影网站
|