tomcat 几种连接池配置代码(包括tomcat5.0,tomcat5.5x,tomcat6.0)
程序员文章站
2022-07-09 17:32:48
tomcat6.0连接池配置 1.配置tomcat下的conf下的context.xml文件,在之间添加连接池配置: 复制代码 代码如下:
tomcat6.0连接池配置
1.配置tomcat下的conf下的context.xml文件,在之间添加连接池配置:
<resource name="jdbc/oracle"
auth="container"
type="javax.sql.datasource"
driverclassname="oracle.jdbc.driver.oracledriver"
url=" jdbc:oracle:thin:@host:port:databse"
username=" user "
password="password"
maxactive="100"
maxidle="30"
maxwait="10000" />
2.配置你的应用下的web.xml中的之间加入:
<resource-ref>
<description>db connection</description>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.datasource</res-type>
<res-auth>container</res-auth>
</resource-ref>
3.把连接数据库的第三方驱动放到common/lib下面就ok了
4.测试程序我就不写了
tomcat5.5x连接池配置
方式一、全局数据库连接池
1、通过管理界面配置连接池,或者直接在tomcat\conf\server.xml的globalnamingresources中增加
<resource name="jdbc/mydb"
type="javax.sql.datasource"
password="mypwd"
driverclassname="com.microsoft.jdbc.sqlserver.sqlserverdriver"
maxidle="2"
maxwait="5000"
validationquery="select 1"
username="sa"
url="jdbc:microsoft:sqlserver://localhost:1433;databasename=mydb"
maxactive="4"/>
2、在tomcat\webapps\myapp\meta-inf\context.xml的context中增加:
<resourcelink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.datasource"/>
这样就可以了。
方式二、全局数据库连接池
1、同上
2、在tomcat\conf\context.xml的context中增加:
<resourcelink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.datasource"/>
方式三、局部数据库连接池
只需在tomcat\webapps\myapps\meta-inf\context.xml的context中增加:
<resource name="jdbc/mydb" type="javax.sql.datasource" password="mypwd" driverclassname="com.microsoft.jdbc.sqlserver.sqlserverdriver" maxidle="2" maxwait="5000" validationquery="select 1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;databasename=mydb" maxactive="4"/>
参数说明:
driveclassname:jdbc驱动类的完整的名称;
maxactive:同时能够从连接池中被分配的可用实例的最大数;
maxidle:可以同时闲置在连接池中的连接的最大数;
maxwait:最大超时时间,以毫秒计;
password:用户密码;
url:到jdbc的url连接;
user:用户名称;
validationquery:用来查询池中空闲的连接。
以上三种方式在tomcat 5.5.4下都可以。另外,sql server的jdbc driver是从微软网站上下载的sql server jdbc (sp3)。
tomcat5.0连接池配置
在tomcat 的下面路径(tomcat \conf\catalina\localhost)下建一个xml文件,内容如下
<resource name="jdbc/test" auth="container" type="javax.sql.datasource"/>
<resourceparams name="jdbc/test">
<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.
-->
<parameter>
<name>maxwait</name>
<value>10000</value>
</parameter>
<!-- mysql db username and password for db connections -->
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>test</value>
</parameter>
<!-- class name for jdbc driver -->
<parameter>
<name>driverclassname</name>
<value>net.sourceforge.jtds.jdbc.driver</value>
</parameter>
<!-- autocommit setting. this setting is required to make
hibernate work. or you can remove calls to commit(). -->
<parameter>
<name>defaultautocommit</name>
<value>true</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:jtds:sqlserver://url/filedb;charset=gb2312;autoreconnect=true</value>
</parameter>
<!-- recover abandoned connections -->
<parameter>
<name>removeabandoned</name>
<value>true</value>
</parameter>
<!-- set the number of seconds a db connection has been idle
before it is considered abandoned.
-->
<parameter>
<name>removeabandonedtimeout</name>
<value>60</value>
</parameter>
<!-- log a stack trace of the code which abandoned the db
connection resources.
-->
<parameter>
<name>logabandoned</name>
<value>true</value>
</parameter>
</resourceparams>
1.配置tomcat下的conf下的context.xml文件,在之间添加连接池配置:
复制代码 代码如下:
<resource name="jdbc/oracle"
auth="container"
type="javax.sql.datasource"
driverclassname="oracle.jdbc.driver.oracledriver"
url=" jdbc:oracle:thin:@host:port:databse"
username=" user "
password="password"
maxactive="100"
maxidle="30"
maxwait="10000" />
2.配置你的应用下的web.xml中的之间加入:
复制代码 代码如下:
<resource-ref>
<description>db connection</description>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.datasource</res-type>
<res-auth>container</res-auth>
</resource-ref>
3.把连接数据库的第三方驱动放到common/lib下面就ok了
4.测试程序我就不写了
tomcat5.5x连接池配置
方式一、全局数据库连接池
1、通过管理界面配置连接池,或者直接在tomcat\conf\server.xml的globalnamingresources中增加
复制代码 代码如下:
<resource name="jdbc/mydb"
type="javax.sql.datasource"
password="mypwd"
driverclassname="com.microsoft.jdbc.sqlserver.sqlserverdriver"
maxidle="2"
maxwait="5000"
validationquery="select 1"
username="sa"
url="jdbc:microsoft:sqlserver://localhost:1433;databasename=mydb"
maxactive="4"/>
2、在tomcat\webapps\myapp\meta-inf\context.xml的context中增加:
<resourcelink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.datasource"/>
这样就可以了。
方式二、全局数据库连接池
1、同上
2、在tomcat\conf\context.xml的context中增加:
复制代码 代码如下:
<resourcelink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.datasource"/>
方式三、局部数据库连接池
只需在tomcat\webapps\myapps\meta-inf\context.xml的context中增加:
复制代码 代码如下:
<resource name="jdbc/mydb" type="javax.sql.datasource" password="mypwd" driverclassname="com.microsoft.jdbc.sqlserver.sqlserverdriver" maxidle="2" maxwait="5000" validationquery="select 1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;databasename=mydb" maxactive="4"/>
参数说明:
driveclassname:jdbc驱动类的完整的名称;
maxactive:同时能够从连接池中被分配的可用实例的最大数;
maxidle:可以同时闲置在连接池中的连接的最大数;
maxwait:最大超时时间,以毫秒计;
password:用户密码;
url:到jdbc的url连接;
user:用户名称;
validationquery:用来查询池中空闲的连接。
以上三种方式在tomcat 5.5.4下都可以。另外,sql server的jdbc driver是从微软网站上下载的sql server jdbc (sp3)。
tomcat5.0连接池配置
在tomcat 的下面路径(tomcat \conf\catalina\localhost)下建一个xml文件,内容如下
复制代码 代码如下:
<resource name="jdbc/test" auth="container" type="javax.sql.datasource"/>
<resourceparams name="jdbc/test">
<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.
-->
<parameter>
<name>maxwait</name>
<value>10000</value>
</parameter>
<!-- mysql db username and password for db connections -->
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>test</value>
</parameter>
<!-- class name for jdbc driver -->
<parameter>
<name>driverclassname</name>
<value>net.sourceforge.jtds.jdbc.driver</value>
</parameter>
<!-- autocommit setting. this setting is required to make
hibernate work. or you can remove calls to commit(). -->
<parameter>
<name>defaultautocommit</name>
<value>true</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:jtds:sqlserver://url/filedb;charset=gb2312;autoreconnect=true</value>
</parameter>
<!-- recover abandoned connections -->
<parameter>
<name>removeabandoned</name>
<value>true</value>
</parameter>
<!-- set the number of seconds a db connection has been idle
before it is considered abandoned.
-->
<parameter>
<name>removeabandonedtimeout</name>
<value>60</value>
</parameter>
<!-- log a stack trace of the code which abandoned the db
connection resources.
-->
<parameter>
<name>logabandoned</name>
<value>true</value>
</parameter>
</resourceparams>