Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Jetty/Howto/Configure JNDI Datasource"
m |
m |
||
Line 18: | Line 18: | ||
These examples assume that all of the datasources are declared at the JVM scope, but you can, of course, use other scopes. You can configure all JNDI resources in a <code>jetty.xml</code> file or in a <code>WEB-INF/jetty-env.xml</code> file, or a context XML file. For more information, see [[Jetty/Feature/JNDI|JNDI]]. | These examples assume that all of the datasources are declared at the JVM scope, but you can, of course, use other scopes. You can configure all JNDI resources in a <code>jetty.xml</code> file or in a <code>WEB-INF/jetty-env.xml</code> file, or a context XML file. For more information, see [[Jetty/Feature/JNDI|JNDI]]. | ||
− | |||
==Pooling DataSources== | ==Pooling DataSources== | ||
− | Enables connection pooling. Connection pooling | + | Enables connection pooling. Connection pooling lets you reuse an existing connection instead of creating a new connection to the database.This is highly efficient in terms of memory allocation and speed of the request to the database. We highly recommend this option for production environments. |
===c3p0=== | ===c3p0=== | ||
Line 96: | Line 95: | ||
==Non-pooling DataSources== | ==Non-pooling DataSources== | ||
− | If you | + | If you are deploying in a production environment, use the Pooling DataSources instead. |
===MySQL=== | ===MySQL=== | ||
Line 165: | Line 164: | ||
</source> | </source> | ||
− | For more information please | + | For more information please see [http://download.oracle.com/docs/cd/B14117_01/java.101/b10979/conncache.htm#CDEBCBJC|this link]. |
===PostgreSQL=== | ===PostgreSQL=== |
Revision as of 14:32, 18 August 2011
Contents
Introduction
This document provides examples of configuring a JNDI datasource for various databases.
These examples all correspond to a <resource-ref>
in web.xml
:
<resource-ref> <description>My DataSource Reference</description> <res-ref-name>jdbc/DSTest</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
These examples assume that all of the datasources are declared at the JVM scope, but you can, of course, use other scopes. You can configure all JNDI resources in a jetty.xml
file or in a WEB-INF/jetty-env.xml
file, or a context XML file. For more information, see JNDI.
Pooling DataSources
Enables connection pooling. Connection pooling lets you reuse an existing connection instead of creating a new connection to the database.This is highly efficient in terms of memory allocation and speed of the request to the database. We highly recommend this option for production environments.
c3p0
Connection pooling, available at http://repo1.maven.org/maven2/c3p0/c3p0/0.9.1.2/c3p0-0.9.1.2.jar
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/DSTest</Arg> <Arg> <New class="com.mchange.v2.c3p0.ComboPooledDataSource"> <Set name="driverClass">org.some.Driver</Set> <Set name="jdbcUrl">jdbc.url</Set> <Set name="user">jdbc.user</Set> <Set name="password">jdbc.pass</Set> </New> </Arg> </New>
dbcp
Connection pooling, available at http://repo1.maven.org/maven2/commons-dbcp/commons-dbcp/1.2/commons-dbcp-1.2.jar
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/DSTest</Arg> <Arg> <New class="org.apache.commons.dbcp.BasicDataSource"> <Set name="driverClassName">org.some.Driver</Set> <Set name="url">jdbc.url</Set> <Set name="username">jdbc.user</Set> <Set name="password">jdbc.pass</Set> </New> </Arg> </New>
Atomikos 3.3.2+
Connection pooling + XA transactions.
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/DSTest</Arg> <Arg> <New class="com.atomikos.jdbc.AtomikosDataSourceBean"> <Set name="minPoolSize">2</Set> <Set name="maxPoolSize">50</Set> <Set name="xaDataSourceClassName">com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</Set> <Set name="UniqueResourceName">DSTest</Set> <Get name="xaProperties"> <Call name="setProperty"> <Arg>url</Arg> <Arg>jdbc:mysql://localhost:3306/databasename</Arg> </Call> <Call name="setProperty"> <Arg>user</Arg> <Arg>some_username</Arg> </Call> <Call name="setProperty"> <Arg>password</Arg> <Arg>some_password</Arg> </Call> </Get> </New> </Arg> </New>
Non-pooling DataSources
If you are deploying in a production environment, use the Pooling DataSources instead.
MySQL
Implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/DSTest</Arg> <Arg> <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"> <Set name="Url">jdbc:mysql://localhost:3306/databasename</Set> <Set name="User">user</Set> <Set name="Password">pass</Set> </New> </Arg> </New>
SQL Server 2000
Implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/DSTest</Arg> <Arg> <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource"> <Set name="User">user</Set> <Set name="Password">pass</Set> <Set name="DatabaseName">dbname</Set> <Set name="ServerName">localhost</Set> <Set name="PortNumber">1433</Set> </New> </Arg> </New>
Oracle 9i/10g
Implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/DSTest</Arg> <Arg> <New class="oracle.jdbc.pool.OracleDataSource"> <Set name="DriverType">thin</Set> <Set name="URL">jdbc:oracle:thin:@fmsswdb1:10017:otcd</Set> <Set name="User">xxxx</Set> <Set name="Password">xxxx</Set> <Set name="connectionCachingEnabled">true</Set> <Set name="connectionCacheProperties"> <New class="java.util.Properties"> <Call name="setProperty"> <Arg>MinLimit</Arg> <Arg>5</Arg> </Call> <!-- put the other properties in here too --> </New> </Set> </New> </Arg> </New>
For more information please see [http://download.oracle.com/docs/cd/B14117_01/java.101/b10979/conncache.htm#CDEBCBJC