wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Log 4j JDBC appender" Watch "Log 4j JDBC appender" New topic
Author

Log 4j JDBC appender

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Hello,

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
Loader.java:199)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClass
Loader.java:224)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
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}" />
</layout>
</appender>

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

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

Thanks,
Trupti
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(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at org.apache.log4j.jdbc.JDBCAppender.getConnection(JDBCAppender.java:19
7)

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

Thanks,
Trupti
Ulf Dittmer
Marshal

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


Ping & DNS - my free Android networking tools app
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?

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

Joined: Mar 22, 2005
Posts: 41127
    
  45
Moved to JDBC forum.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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: http://aspose.com/file-tools
 
subject: Log 4j JDBC appender
 
Similar Threads
How to use log4j.jdbcplus.JDBCAppender in log4j.xml
log4j XML properties file problem.
JAXB with log.xml
Separate log file
unable to debug log4j