public class JNDIConnectionSource extends ConnectionSourceSkeleton
JNDIConnectionSource
is an implementation of
ConnectionSource
that obtains a DataSource
from a
JNDI provider and uses it to obtain a Connection
. It is
primarily designed to be used inside of J2EE application servers or
application server clients, assuming the application server supports remote
access of DataSource
s. In this way one can take
advantage of connection pooling and whatever other goodies the application
server provides.
Sample configuration:
<connectionSource class="org.apache.log4j.jdbc.JNDIConnectionSource"> <param name="jndiLocation" value="jdbc/MySQLDS" /> </connectionSource>
Sample configuration (with username and password):
<connectionSource class="org.apache.log4j.jdbc.JNDIConnectionSource"> <param name="jndiLocation" value="jdbc/MySQLDS" /> <param name="username" value="myUser" /> <param name="password" value="myPassword" /> </connectionSource>
Note that this class will obtain an InitialContext
using the no-argument constructor. This will usually work when executing
within a J2EE environment. When outside the J2EE environment, make sure
that you provide a jndi.properties file as described by your JNDI
provider's documentation.
repository
HSQL_DIALECT, MSSQL_DIALECT, MYSQL_DIALECT, ORACLE_DIALECT, POSTGRES_DIALECT, UNKNOWN_DIALECT
Constructor and Description |
---|
JNDIConnectionSource() |
Modifier and Type | Method and Description |
---|---|
void |
activateOptions() |
Connection |
getConnection()
Obtain a
Connection for use. |
String |
getJndiLocation()
Returns the jndiLocation.
|
void |
setJndiLocation(String jndiLocation)
Sets the jndiLocation.
|
discoverConnnectionProperties, getOverriddenSupportsGetGeneratedKeys, getPassword, getSQLDialectCode, getUser, setOverriddenSupportsGetGeneratedKeys, setPassword, setUser, supportsBatchUpdates, supportsGetGeneratedKeys
getLogger, getLoggerRepository, getNonFloodingLogger, resetErrorCount, setLoggerRepository
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setLoggerRepository
public void activateOptions()
OptionHandler.activateOptions()
public Connection getConnection() throws SQLException
ConnectionSource
Connection
for use. The client is
responsible for closing the Connection
when it is no
longer required.SQLException
- if a Connection
could not be
obtainedConnectionSource.getConnection()
public String getJndiLocation()
public void setJndiLocation(String jndiLocation)
jndiLocation
- The jndiLocation to setCopyright © 2002-2017 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache Chainsaw, Chainsaw, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.