Log4J JDBCAppender issue

Hi,

I am using Log4j JDBCAppender to log messages in the Data base.

The sql i am using is

log4j.appender.loggingdb.sql = INSERT INTO ACRT1.MESSAGE_TABLE (MESSAGE_CODE, MESSAGE_ID, MESSAGE_TEXT) VALUES ('HI12', 'F','@MSG@')

I call Logger.info(message); in my java class. Now this fires the SQL and the message i have given above is inserted in the DB.

What i want is that instead of hardcoding the first 2 values I want to pass those values also from my java class.

How do i pass the values to the sql.

I am using a properties file for configuration.

[605 byte] By [javitea] at [2007-11-27 10:12:55]
# 1

> log4j.appender.loggingdb.sql = INSERT INTO ACRT1.MESSAGE_TABLE (MESSAGE_CODE, MESSAGE_ID, MESSAGE_TEXT) VALUES ('HI12', 'F','@MSG@')

What's @MSG@? Is this a placeholder? You can use translate this at runtime if necessary. However what would be better is to use a prepared statement, as this is parameterised so would suit what you are trying to do.

http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html

curry_monstera at 2007-7-28 15:23:26 > top of Java-index,Java Essentials,Java Programming...
# 2

> The sql i am using is

>

> log4j.appender.loggingdb.sql = INSERT INTO

> ACRT1.MESSAGE_TABLE (MESSAGE_CODE, MESSAGE_ID,

> MESSAGE_TEXT) VALUES ('HI12', 'F','@MSG@')

>

> I call Logger.info(message); in my java class. Now

> this fires the SQL and the message i have given above

> is inserted in the DB.

%m is used to indicate the placeholder for the message, as far as I remember.

aniseeda at 2007-7-28 15:23:26 > top of Java-index,Java Essentials,Java Programming...
# 3

@MSG@ works, this is a variable which has to be dynamically replaced by the message.

The message i give in

logger.info("Hi Testing the JDBCAppender");

i.e. Hi Testing the JDBCAppender will be replacing @MSG@ in the query.

Similarly i want to dynamically replace first two values also. Is there a configuration to do that?

javitea at 2007-7-28 15:23:26 > top of Java-index,Java Essentials,Java Programming...