Jetty Logo
Version: 9.2.3.v20140905
Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Datasource Examples

Pooling DataSources
Non-pooling DataSources

Here are examples of configuring a JNDI datasource for various databases.

Note

Read Configuring DataSources in Configuring JNDI for more information about configuring datasources.

All of these examples correspond to a resource-ref in web.xml.

These examples assume that all of the datasources are declared at the JVM scope, but you can use other scopes if desired. 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. See the section Deciding Where to Declare Resources for more information.

Important

You must provide Jetty with the libraries necessary to instantiate the datasource you have configured by putting the corresponding Jar in JETTY_HOME/lib/ext.

Pooling DataSources

Pooling datasources enables connection pooling, which 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.

The following is a list of the pooled datasource examples we have worked with in the past:

HikariCP

Connection pooling, available at HikariCP Download. All configuration options for HikariCP are described here: HikariCP documentation.

BoneCP

Connection pooling, available at BoneCP Download. All configuration options for BoneCP are described here: BoneCP API.

c3p0

Connection pooling, available at c3p0 Jar.

DBCP

Connection pooling, available at dbcp Jar.

Atomikos 3.3.2+

Connection pooling + XA transactions.

MySQL

Implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource.

PostgreSQL

Implements javax.sql.ConnectionPoolDataSource

DB2

Implements javax.sql.ConnectionPoolDataSource

Non-pooling DataSources

If you are deploying in a production environment, we highly recommend using a Pooling DataSource. Since that is not always an option we have a handful of examples for non-pooling datasources listed here as well.

The following is a list of the non-pooled datasource examples:

SQL Server 2000

Implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource.

Oracle 9i/10g

Implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource.

For more information, refer to: Oracle Database JDBC documentation.

PostgreSQL

Implements javax.sql.DataSource.

Sybase

Implements javax.sql.DataSource.

DB2

Implements javax.sql.DataSource.

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-10-31T01:00:26-07:00)