</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<!-- Use the removeAbandonedTimeout parameter to set the number of seconds a DB connection has been idle before it is considered abandoned. -->
<value>60</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<!-- Log a stack trace of the code which abandoned -->
<value>false</value>
</parameter>
</ResourceParams>
</Context>
注意:
l所有的入口和资源都放在JNDI命名空间里的java:comp/env段里
l设置JNDI资源要在$CATALINA_HOME/conf/server.xml文件里使用下列标志符:
1) <Resource>--设置应用程序可用的资源的名字和类型(同上面说的<resource-ref>等价)。
2) <ResourceParams>--设置Java资源类工厂的名称或将用的JavaBean属性。
上述这些标志符必须放在<Context>和</Context>之间
(2)、拷贝SQLServer的JDBC驱动程序到Tomcat的/common/lib目录下
(3)、在程序中利用数据源来访问
try
{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/webmis");
Connection con=ds.getConnection();
}
catch (NamingException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
5、在server.xml文件中与数据源的描述相关的标签含义
lmaxActive连接池的最大连接数。设为0表示无限制。
lmaxIdle连接的最大空闲时间。超过此空闲时间,连接将被标记为不可用,然后被释放。设为0表示无限制。
lmaxWait最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
lremoveAbandoned回收被遗弃的(一般是忘了释放的)连接到连接池中。
lremoveAbandonedTimeout连接过多长时间不用将被视为被遗弃而收回连接池中。
llogAbandoned将被遗弃的连接的回收记入日志。
ldriverClassName JDBC驱动程序。
lurlDSN连接字符串
6、在Web应用的web.xml文件中引用该资源
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-27620-12.html
估计是理亏
加速军事化