File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes Log 4j JDBC appender Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Log 4j JDBC appender" Watch "Log 4j JDBC appender" New topic

Log 4j JDBC appender

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613

I am trying to use the log4j JDBC appender with mySQL. I am getting below error message:
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassNotFoundException: org.apache.log4j.jdbcplus.JDBCAppender
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClass
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClass
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)

I have put the log4j jar file in the classpath. My log4j configuration is as below:
<appender name="JDBC" class="org.apache.log4j.jdbcplus.JDBCAppender">
<param name="url" value="jdbc:mysql://localhost:3306/mysql" />
<param name="username" value="root" />
<param name="password" value="root" />
<param name="sql" value="INSERT INTO LOGTEST (id, prio, cat, thread, msg) VALUES (@INC@, '@PRIO@', '@CAT@', '@THREAD@', '@MSG@')" />
<param name="buffer" value="1" />
<param name="commit" value="true" />
<param name="dbclass" value="com.mysql.jdbc.Driver" />
<param name="quoteReplace" value="true" />
<param name="throwableMaxChars" value="3000" />
<param name="layoutPartsDelimiter" value="#-#" />
<layout class="org.apache.log4j.PatternLayout">
<!-- conversion pattern with 4 parts separated by #-#, second part is empty -->
<param name="ConversionPattern" value="[%t] %m#-##-#%d{dd.MM.yyyy}#-#%d{HH:mm:ss}" />

<!--<appender-ref ref="def"/>-->
<!--<appender-ref ref="RollingFile" />-->
<appender-ref ref="JDBC" />

Can someone please help me out what am I doing wrong?

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
now I am getting below exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(
at java.sql.DriverManager.getConnection(
at org.apache.log4j.jdbc.JDBCAppender.getConnection(

There was some mistake in the earlier configuration. I corrected that so am getting above exception.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39537
Is the MySQL JDBC driver in your classpath? That's the error you would get if it wasn't.

Ping & DNS - updated with new look and Ping home screen widget
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
The driver is in the classpath, but the configuration had lower case driver name. I changed so do not get that error any more but now it seems I have problem with my SQL statement.

The statement runs with no problem from mySQL console but when I run it through the config file I get below error:

log4j:ERROR Failed to excute sql
java.sql.SQLException: You have an error in your SQL syntax; check the manual th
at corresponds to your MySQL server version for the right syntax to use near '[E
xecuteThread: '1' for queue: 'weblogic.kernel.System'] Entering net.mycompany.'
at line 1

The SQLstatement is given below:
<param name="sql" value="INSERT INTO test (message) VALUES ('%d - %c - %p - %m'); "/>

Can someone please let me know what is wrong in above SQL?

[ April 25, 2006: Message edited by: trupti nigam ]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39537
Moved to JDBC forum.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18114

What's wrong with that SQL? Well, the error message says that it includes this:
[ExecuteThread: '1' for queue: 'weblogic.kernel.System'] Entering net.mycompany.
I think that when the appender replaces %d and so on by the replacement values, if the replacement values contain quotes then the SQL gets fouled up.
I agree. Here's the link:
subject: Log 4j JDBC appender
Similar Threads
unable to debug log4j
Separate log file
JAXB with log.xml
How to use log4j.jdbcplus.JDBCAppender in log4j.xml
log4j XML properties file problem.