SqlServer database connection pool to connect tomcat

First, install the JDBC Driver
The database driver jar file to put (Tomcat_install) \ common \ lib directory

Second, configure the Connection Pool
1. Overall connection pool configuration, Tomcat in any Web application can be configured to use the connection pool.
In Tomcat's server.xml file to add the following node GlobalNamingResources, connection pool settings
<Resource
name = "jdbc / poolName"
auth = "Container"
type = "javax.sql.DataSource"
maxActive = "100"
maxIdle = "30"
maxWait = "10000"
username = "sa"
password = "password"
driverClassName = "net.sourceforge.jtds.jdbc.Driver"
url = "jdbc: jtds: sqlserver: / / localhost: 1433; DatabaseName = pubs" />
Note: name for the connection pool of global JNDI name

Set at the overall situation inside context.xml visit Name:
<ResourceLink
global = "jdbc / poolName"
name = "jdbc / poolName"
type = "javax.sql.DataSource" />

2. Partial connection pool configuration (recommended)
At $ TOMCAT_HOME $ / conf / Catalina / localhost / directory create a new xml file, the xml file should be released with your Web application directory name the same, if for webappname.xml, add the following (configured Tomcat external virtual directory is at get here, and ha!)
<Context path = "/ webappname" docBase = "d: / webappname" debug = "0"
reloadable = "true" crossContext = "true">
<Resource
name = "jdbc / poolName"
auth = "Container"
type = "javax.sql.DataSource"
maxActive = "100"
maxIdle = "30"
maxWait = "10000"
username = "sa"
password = "password"
driverClassName = "net.sourceforge.jtds.jdbc.Driver"
url = "jdbc: jtds: sqlserver: / / localhost: 1433; DatabaseName = pubs" />
<ResourceLink global = "jdbc / poolName" name = "jdbc / poolName"
type = "javax.sql.DataSource" />
</ Context>

Configure Tomcat \ webapps \ webappname \ WEB-INF \ web.xml, set reference source
<resource-ref>
<description> my DB Connection </ description>
<res-ref-name> jdbc / poolName </ res-ref-name> the same as server.xml
<res-type> javax.sql.DataSource </ res-type>
<res-auth> Container </ res-auth>
</ resource-ref>
Configuration \ Tomcat \ webapps \ webappname \ META-INF \ context.xml, the data source connection settings are as follows:
<? xml version ='1 .0 'encoding =' utf-8 '?>
<Context path = "/ webappname" docBase = "webappname" debug = "5"
reloadable = "true" crossContext = "true">
<ResourceLink name = "jdbc / poolName" global = "jdbc / poolName"
type = "javax.sql.DataSource" />
</ Context>

Context ctx = (Context) new InitialContext (). Lookup ( "java: comp / env");
DataSource ds = (DataSource) ctx.lookup ( "jdbc / poolName);
Connection conn = ds.getConnection ();
conn.close ();

Do not forget to call on the Connection object close () method, note: here will not turn off the
Connection, but will be back on the Connection Database Connection Pool.

-------------------------------------------------- ----------------------------------
Also can be injected into ways to call the connection pool, that is, in Hibernate configuration file hibernate.cfg.xm l call in the JSP container configured connection pool later, and then in the Hibernate configuration file called the system connection pool settings, the key code are summarized below:

<session-factory>
<! --
<property name="jndi.class"> </ property>
<property name="jndi.url"> </ property>
->
<property name="connection.datasource"> java: comp / env / jdbc / poolName </ property>
<property name="show_sql"> false </ property>
<property name="dialect"> org.hibernate.dialect.SybaseDialect </ property>
</ session-factory>

Hibernate specific use, please refer to the relevant detailed information.

分类:Java 时间:2009-03-01 人气:2947
分享到:
blog comments powered by Disqus

相关文章

  • JDBC technology and database connection pooling feature (reprint) 2009-10-02

    JDBC Basics First, access the database using JDBC basic steps: A. loading JDBC driver B. definition connection URL C. establish a connection D. create a Statement object E. execute a query or update F. The results dealing with G. Close the connection

  • The basic principles of database connection pool 2010-06-11

    Traditional database connection (refer to the basic realization through DriverManager and DataSource to connect), a database connection objects are corresponding to a physical database connection, database connection and the closure of the establishm

  • Hibernate for a summary of the database connection pool 2010-07-31

    A need to set the property: Minimum connection - start immediately after the application number of open connections, and follow-up to the minimum number of connections to maintain. Maximum number of connections - most applications can use the number

  • tomcat6 database connection pool (DBCP) configuration (mysql for example) 2011-05-03

    Because JNDI configuration in tomcat5.0 and tomcat5.5.x been modified, so the previous tomcat6 the JNDI configuration is somewhat different, this article only describes the configuration database connection pool tomcat6 below. tomcat support JDBC2.0

  • MySQL 5 database connection time-out to solve the problem 2011-02-14

    Recently met a mysql5 database problem. Is a standard servlet / Tomcat web application, the background using mysql database. The problem is after a night stand the next morning is always the first login failure. View logs found the following errors:

  • How to connect sql server database connection pool configuration Tomcat 2010-02-24

    How to connect SQL Server database (Tomcat connection pool configuration) (reproduced) Source: http://www.blogjava.net/guming123416/articles/28002.html Version is relatively new, on-line many are saying is Tomcat 4, this is 5.0. How to connect SQL Se

  • JDBC database connection pool 2010-05-07

    In tomcat6.0, server2000 database and connection pool configuration under myeclipse (with MySQL database similar) Tomcat 5 configuration data source data source with Tomcat 5.5 configured with many differences, Tomcat 6 of the data source configurati

  • JDBC database connection pool Statment 2010-09-08

    1. Foreword   database applications, in many software systems are often used, is indispensable for the development of supporting large-scale systems. But if not well managed database resources (such as: failure to make timely recovery of the databa

  • JDBC database connection pool and the principle of achieving 2010-11-07

    1. Introduction Database applications, in many software systems are often used, is indispensable to the development of supporting large-scale systems. But if not well managed database resources (such as: failure to make timely recovery of the databas

  • A simple implementation of JDBC database connection pool 2011-01-06

    Of :snapbug From :CSDN   directory :   1. Introduction   2. Connection pool technology background   2.1 JDBC   2.2 JDBC Connection Pool   2.3 connection pool (ConnectionPool) And resource management   3. Simple JDBC Implementation of co

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.643 (s). 12 q(s)