JNDI数据库连接池的配置

<!-- The contents of this file will be loaded for each web application -->

1.将tomcat的conf/目录下的context.xml 修改成如下的操作
<Context reload="true">

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
	
    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
	<Resource
		name = "jdbc/DBSource" 
		type ="javax.sql.DataSource"
		maxActive = "4"
		maxIdle="2"
		username ="root"
		maxWait ="5000"
		driverClassName ="com.mysql.jdbc.Driver"
		password ="admin"
		url="jdbc:mysql://localhost:3306/person"
		/>
	<!	name --数据源名
		driverClassName 使用的JDBC驱动程序的完整类名
		url 数据库
		username 数据库的用户名
		password 数据库的密码
		type 指定该资源的类型,这里为DataSource
		maxActive 可以同时为该连接池分配的活动连接实例的最大数
		maxIdle: 该连接池中可空间的连接的最大数
		maxWait 在没有可连接的时候连接池在抛出异常前等待的最大毫米数
		validationQuery 在连接被返回应用程序前,连接池用来验证连接的sql查询语句
	-->
</Context>

 数据库中调用才有如下方式
<!-- Context context = new InitialContext();
	DataSource ds = (DataSource)context.lookup("java:comp/enc/jdbc/DBSource");
	Connection conn = ds.getConnection();

-->

2.将mysql驱动拷贝到tomcat/lib 目录下

3.over

转载于:https://my.oschina.net/zlp5201/blog/404188

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值