Package org.apache.log4j.db
Class DriverManagerConnectionSource
- java.lang.Object
-
- org.apache.log4j.spi.ComponentBase
-
- org.apache.log4j.db.ConnectionSourceSkeleton
-
- org.apache.log4j.db.DriverManagerConnectionSource
-
- All Implemented Interfaces:
ConnectionSource,Component,org.apache.log4j.spi.OptionHandler
public class DriverManagerConnectionSource extends ConnectionSourceSkeleton
The DriverManagerConnectionSource is an implementation ofConnectionSourcethat obtains the Connection in the traditional JDBC manner based on the connection URL.Note that this class will establish a new Connection for each call to
getConnection(). It is recommended that you either use a JDBC driver that natively supported Connection pooling or that you create your own implementation ofConnectionSourcethat taps into whatever pooling mechanism you are already using. (If you have access to a JNDI implementation that supportsDataSources, e.g. within a J2EE application server, seeJNDIConnectionSource). See below for a configuration example that uses the commons-dbcp package from Apache.Sample configuration:
<connectionSource class="org.apache.log4j.jdbc.DriverManagerConnectionSource"> <param name="driver" value="com.mysql.jdbc.Driver" /> <param name="url" value="jdbc:mysql://localhost:3306/mydb" /> <param name="username" value="myUser" /> <param name="password" value="myPassword" /> </connectionSource>If you do not have another connection pooling mechanism built into your application, you can use the commons-dbcp package from Apache:
<connectionSource class="org.apache.log4j.jdbc.DriverManagerConnectionSource"> <param name="driver" value="org.apache.commons.dbcp.PoolingDriver" /> <param name="url" value="jdbc:apache:commons:dbcp:/myPoolingDriver" /> </connectionSource>Then the configuration information for the commons-dbcp package goes into the file myPoolingDriver.jocl and is placed in the classpath. See the commons-dbcp documentation for details.- Author:
- Ray DeCampo
-
-
Field Summary
-
Fields inherited from class org.apache.log4j.spi.ComponentBase
repository
-
Fields inherited from interface org.apache.log4j.db.ConnectionSource
HSQL_DIALECT, MSSQL_DIALECT, MYSQL_DIALECT, ORACLE_DIALECT, POSTGRES_DIALECT, UNKNOWN_DIALECT
-
-
Constructor Summary
Constructors Constructor Description DriverManagerConnectionSource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateOptions()ConnectiongetConnection()Obtain aConnectionfor use.StringgetDriverClass()Returns the name of the driver class.StringgetUrl()Returns the url.voidsetDriverClass(String driverClass)Sets the driver class.voidsetUrl(String url)Sets the url.-
Methods inherited from class org.apache.log4j.db.ConnectionSourceSkeleton
discoverConnnectionProperties, getOverriddenSupportsGetGeneratedKeys, getPassword, getSQLDialectCode, getUser, setOverriddenSupportsGetGeneratedKeys, setPassword, setUser, supportsBatchUpdates, supportsGetGeneratedKeys
-
Methods inherited from class org.apache.log4j.spi.ComponentBase
getLogger, getLoggerRepository, getNonFloodingLogger, resetErrorCount, setLoggerRepository
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.log4j.spi.Component
setLoggerRepository
-
-
-
-
Method Detail
-
activateOptions
public void activateOptions()
-
getConnection
public Connection getConnection() throws SQLException
Description copied from interface:ConnectionSourceObtain aConnectionfor use. The client is responsible for closing theConnectionwhen it is no longer required.- Throws:
SQLException- if aConnectioncould not be obtained- See Also:
ConnectionSource.getConnection()
-
getUrl
public String getUrl()
Returns the url.- Returns:
- String
-
setUrl
public void setUrl(String url)
Sets the url.- Parameters:
url- The url to set
-
getDriverClass
public String getDriverClass()
Returns the name of the driver class.- Returns:
- String
-
setDriverClass
public void setDriverClass(String driverClass)
Sets the driver class.- Parameters:
driverClass- The driver class to set
-
-