• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log 4j JDBC appender

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the MySQL JDBC driver in your classpath? That's the error you would get if it wasn't.
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to JDBC forum.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
grapes are vegan food pellets. Eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic