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.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of SqlServer database connection pool to connect tomcat

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • hibernate to use the principle of

    The use of hibernate, implementation of data persistence. Has the following several processes. One configuration database connection information. Hibernate.config 2 configuration mapping. 3 use: the use of the process are the following steps: 3.1: Ge ...

  • myeclipse plugin

    myeclipsePlug-ins? 1.tomcatPlugin(Start tomcat ):http ://www.sysdeo.com/eclipse/tomcatPlugin.html,2.xVersions of eclipse 3 version 2 .1Version doesn't work. 2.Lomboz(Development of jsp program ,jspDynamic prompt, debugging ):http://forge.objectweb.org/pro

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • spring struts2.0 hibernate environmental structures .. despair carried out more than one hour only with good.

    http://www.qqread.com/java/2008/06/f413762.html Look here. . Note added myeclipse support spring when necessary add the commons-dbcp database connection pool package. And to add hibernate support. . Finally add struts2 support. . Oh the lazy point. . . fu

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries