明月松间照 清泉石上流
——— 兵临城下   猫科动物
posts - 69, comments - 126, trackbacks - 0, articles - 23
BlogJava
::
首页
::
新随笔
::
联系
::
聚合
::
管理
tomcat配置jndi数据源小记 (引用自junmy)
Posted on 2007-01-07 11:26
兵临城下
阅读(34)
评论(0)
编辑
收藏
所属分类:
Tomcat
tomcat配置jndi数据源小记
1.在server.xml中加入。
这可以登陆后台配置。。
<!--
configure DataSource. Add the following code into server.xml
-->
<
Context
path
= " /test "
docBase
= "test "
debug
= " 0 "
reloadable
= " true "
>
<
Resource
name
= " jdbc/first "
auth
= " Container "
type
= " javax.sql.DataSource "
/>
<
ResourceParams
name
= " jdbc/first "
>
<
parameter
>
<
name
>
factory
</
name
>
<
value
>
org.apache.commons.dbcp.BasicDataSourceFactory
</
value
>
</
parameter
>
<!--
Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<
parameter
>
<
name
>
maxActive
</
name
>
<
value
>
100
</
value
>
</
parameter
>
<!--
Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<
parameter
>
<
name
>
maxIdle
</
name
>
<
value
>
30
</
value
>
</
parameter
>
<!--
Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to - 1 to wait indefinitely.
Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to - 1 to wait indefinitely.
-->
<
parameter
>
<
name
>
maxWait
</
name
>
<
value
>
10000
</
value
>
</
parameter
>
<!--
MySQL dB username and password for dB connections
-->
<
parameter
>
<
name
>
username
</
name
>
<
value
>
dbuser
</
value
>
</
parameter
>
<
parameter
>
<
name
>
password
</
name
>
<
value
>
1234
</
value
>
</
parameter
>
<!--
Class name for mm.mysql JDBC driver
-->
<
parameter
>
<
name
>
driverClassName
</
name
>
<
value
>
com.mysql.jdbc.Driver
</
value
>
</
parameter
>
<!--
The JDBC connection url for connecting to your MySQL dB.
The autoReconnect = true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<
parameter
>
<
name
>
url
</
name
>
<
value
>
jdbc:mysql: // localhost:3306/test?autoReconnect=true
</
value
>
</
parameter
>
</
ResourceParams
>
</
Context
>
在工程web-xml中加入以下代码
<
resource-ref
>
<
description
>
DB Connection
</
description
>
<
res-ref-name
>
jdbc/test
</
res-ref-name
>
<
res-type
>
javax.sql.DataSource
</
res-type
>
<
res-auth
>
Container
</
res-auth
>
</
resource-ref
>
jsp 访问。。
导包
<%
@ page
import
=
"
java.util.*
"
%>
<%
@ page
import
=
"
java.sql.*
"
%>
<%
@ page
import
=
"
javax.sql.*
"
%>
<%
@ page
import
=
"
javax.naming.*
"
%>
<%
@ page
import
=
"
com.mysql.jdbc.Connection
"
%>
访问代码
//
建立数据库连接
Context ctx
=
new
InitialContext();
DataSource ds
=
(DataSource)ctx.lookup(
"
java:comp/env/jdbc/test
"
);
con
=
ds.getConnection();
//
创建一个JDBC声明
stmt
=
con.createStatement();
//
有了连接。。就可以做很多事了。。
注意把mysql驱动拷到comcat common/lib下面..
目标:一天整理一点东西。。虽然简单。。但记下来还是有好处的。。
新闻频道
新用户注册
刷新评论列表
标题
姓名
主页
验证码
*
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关链接:
网站导航:
博客园
BlogJava
博客生活
IT博客网
C++博客
PHP博客
博客园社区
管理博客
教师博客
天文博客
汽车博客
足球博客
股票博客
电子博客
管理
相关文章:
css教程–十步学会用css建站(全)
tomcat配置jndi数据源小记 (引用自junmy)
Powered by:
BlogJava
Copyright © 兵临城下
日历
<
2008年9月
>
日
一
二
三
四
五
六
31
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
1
2
3
4
5
6
7
8
9
10
11
常用链接
我的随笔
我的评论
我的参与
最新评论
随笔分类
(64)
essay(11)
J2SE(10)
Java EE(13)
JavaScript(7)
scribble(18)
Spring(5)
随笔档案
(69)
2008年8月 (1)
2008年6月 (2)
2008年5月 (1)
2008年4月 (5)
2007年9月 (1)
2007年7月 (3)
2007年5月 (1)
2007年3月 (1)
2007年2月 (2)
2007年1月 (6)
2006年12月 (10)
2006年11月 (12)
2006年9月 (4)
2006年8月 (7)
2006年7月 (2)
2006年6月 (3)
2006年5月 (2)
2006年4月 (6)
文章分类
(23)
Hibernate(2)
J2EE(11)
JS(2)
Spring(2)
SQL(1)
Struts(3)
Tomcat(2)
相册
一点心得
个人作品
重庆成都之旅
最新随笔
1. 这半年。。。
2. 断翅的天使
3. 生死不离,我数秒等你的消息~~
4. oracle命令:exp、imp
5. 五一前最后一贴!发现一个问题,搞不明白,上来求助!
6. 曲终人散
7. 突然发现,再过三天就是我blog开张两周年了,纪念一下!(无内文)
8. 该断则断
9. oracle bug
10. 近日随想
11. 天热了,人就烦躁了
12. 《魔兽争霸3》 四大种族爆笑小笑话(引用)
13. 一个郁闷了我两天的问题
14. 公司培训记 ----人有点浮躁了
15. 双飞七日游纪念
积分与排名
积分 - 25925
排名 - 326
最新评论
1. re: 这半年。。。[未登录]
哥们儿,外面的世界诱惑太多,成熟起来不容易啊
--FLY
2. re: 五一前最后一贴!发现一个问题,搞不明白,上来求助!
明白了,谢了!
--兵临城下
评论排行榜
1. Spring 整合Struts的问题!(11)
2. J2EE Development without EJB读后随笔(8)
3. 又是JS的问题!最近研究中……(7)
4. singleton的一点疑问(7)
5. 关于数据库count的问题(6)