光の境
光の代碼學(xué)習(xí)基地
BlogJava
首頁
新隨筆
聯(lián)系
聚合
管理
隨筆檔案
2007年9月 (2)
2007年7月 (1)
2007年6月 (1)
2007年4月 (4)
文章檔案
2007年7月 (1)
2007年4月 (1)
最新隨筆
1.?struts2可以直接在頁面中調(diào)用action
2.?struts2中action實現(xiàn)Preparable接口的利弊
3.?IT人員健康工作表
4.?javascript總為這種問題費心力,索性貼在這吧
5.?spring學(xué)習(xí)記錄
6.?smartupload and JExcel
7.?prototype api 中文版
8.?iBatis使用記錄
最新評論
1.?re: struts2中action實現(xiàn)Preparable接口的利弊
這個接口確實不大好,好處是在重載方法prepare方法里可以做初始化
--路人甲
2.?re: prototype api 中文版
79cha.com 頂了
--renren
3.?re: prototype api 中文版
好!很好!非常好!
--whsx_01
4.?re: prototype api 中文版
ding !!!!!
--js
5.?re: struts2中action實現(xiàn)Preparable接口的利弊
關(guān)注中 樓主把學(xué)習(xí)struts2的經(jīng)驗告訴下吧 最近一直研究這個
聯(lián)系方式 wanganyuaa@163.com
qq 86322989
不勝感激
--way
iBatis使用記錄
Posted on 2007-04-07 16:55
它山の石
閱讀(577)
評論(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獲得一個SqlMapClient對象
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)初始化完畢,開始執(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獲得一個SqlMapClient對象
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)初始化完畢,開始執(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ù)
更多評論
2007-04-16 11:24 by
echo
System.out.println(u.getId()+" "+u.getName()+" "+u.getSex()); 請問為什么我運行結(jié)果什么都沒有呢?不知道原因啊 !請教
#
re: iBatis使用記錄
回復(fù)
更多評論
2007-04-18 22:21 by
ryan
不需要在每個方法都初始化iBatis獲得一個SqlMapClient對象吧
#
re: iBatis使用記錄
回復(fù)
更多評論
2007-04-27 19:30 by
它山の石
@echo
我猜你數(shù)據(jù)庫的表中沒有記錄吧
#
re: iBatis使用記錄
回復(fù)
更多評論
2007-04-27 19:31 by
它山の石
@ryan
呵呵這位大俠說的對,確實不用每個方法都初始化,這里只是做為試用而已,呵呵
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
公告
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
java
eamoi
oksonic
評論排行榜
1.?iBatis使用記錄(4)
2.?prototype api 中文版(3)
3.?struts2中action實現(xiàn)Preparable接口的利弊(2)
4.?IT人員健康工作表(0)
5.?javascript總為這種問題費心力,索性貼在這吧(0)
閱讀排行榜
1.?struts2中action實現(xiàn)Preparable接口的利弊(6662)
2.?prototype api 中文版(2445)
3.?struts2可以直接在頁面中調(diào)用action(858)
4.?smartupload and JExcel(718)
5.?iBatis使用記錄(577)
posts - 8, comments - 9, trackbacks - 0, articles - 2
Copyright © 它山の石
主站蜘蛛池模板:
国产成人精品日本亚洲语音
|
国产成人精品久久亚洲高清不卡
|
免费看国产曰批40分钟
|
亚洲а∨精品天堂在线
|
波多野结衣视频在线免费观看
|
特级毛片aaaa免费观看
|
亚洲gv猛男gv无码男同短文
|
日韩欧毛片免费视频
|
特级做a爰片毛片免费看
|
亚洲伊人久久大香线蕉结合
|
亚洲男人的天堂一区二区
|
久久免费动漫品精老司机
|
亚洲天然素人无码专区
|
亚洲伊人久久成综合人影院
|
四虎在线最新永久免费
|
精品在线免费视频
|
亚洲精品国产精品乱码不卞
|
免费鲁丝片一级观看
|
182tv免费视频在线观看
|
亚洲中文字幕乱码一区
|
亚洲卡一卡2卡三卡4麻豆
|
亚洲日本在线观看视频
|
免费国产a国产片高清网站
|
在线免费视频一区二区
|
中文字幕不卡免费高清视频
|
亚洲综合欧美色五月俺也去
|
亚洲最大在线观看
|
国产精品亚洲高清一区二区
|
免费A级毛片无码A
|
免费中文字幕不卡视频
|
亚洲 小说区 图片区 都市
|
久久99九九国产免费看小说
|
182tv免费视视频线路一二三
|
一区二区三区免费电影
|
亚洲熟妇无码一区二区三区
|
亚洲乱码在线视频
|
日韩亚洲人成在线
|
亚洲激情校园春色
|
亚洲av最新在线网址
|
亚洲处破女AV日韩精品
|
亚洲区日韩区无码区
|