First, here is what the relevant settings in the log4j.properties file should look like:
# Set root logger level to DEBUG and its only appender to DB.
# The database logger
log4j.appender.DB.sql=INSERT INTO mytable (mycolmn) VALUES ("%m")
Two things to note:
- I had to specify the driver property because log4j couldn't automatically determine that or was defaulting to an incorrect driver class name. I was using log4j 1.2.12 and MySQL Connector/J version 5.1.5
- The values being inserted in the database need to be enclosed in double quotes (") as opposed to the normal single quote (') you would use in SQL syntax