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]

> 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
> 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.
@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?