放在手边
导航
BlogJava
首页
新随笔
联系
聚合
管理
统计
随笔 - 0
文章 - 5
评论 - 0
引用 - 0
留言簿
(1)
给我留言
查看公开留言
查看私人留言
文章分类
here—others(1)
(rss)
original articles(3)
(rss)
web—others(2)
(rss)
文章档案
2009年7月 (3)
2009年6月 (2)
收藏夹
我的收藏
(rss)
搜索
最新评论
Tomcat6 数据连接池配置
Tomcat6 和 Tomcat5的配置不一样,我按Tomcat5的配置方法,就是报错,以前是把配置写在server.xml里,但在Tomcat6里面是把配置写在conf/context.xml里
把数据库驱动放到lib目录下
配置tomcat下的conf下的context.xml文件,在<context></context>之间添加连接池如下
<
Resource
name
="jdbc/mysql"
auth
="Container"
type
="javax.sql.DataSource"
driverClassName
="com.mysql.jdbc.Driver"
url
="jdbc:mysql://localhost/test"
username
="root"
password
="root"
maxActive
="100"
maxIdle
="30"
配置你的应用下的web.xml中的<web-app></web-app>之间加入
<
resource-ref
>
<
description
>
DB Connection
</
description
>
<
res-ref-name
>
jdbc/mysql
</
res-ref-name
>
<
res-type
>
javax.sql.DataSource
</
res-type
>
<
res-auth
>
Container
</
res-auth
>
</
resource-ref
>
配置好了之后就可以通过下面的方式获取数据库连接
DataSource ds
=
null
;
try
{
InitialContext ctx
=
new
InitialContext();
ds
=
(DataSource)ctx.lookup(
"
java:comp/env/jdbc/mysql
"
);
Connection conn
=
ds.getConnection();
}
catch
(Exception ex){
ex.printStackTrace();
}
posted on 2009-06-18 13:53
兰兰
阅读(105)
评论(0)
编辑
收藏
所属分类:
here—others
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理