如题.最好给点代码.环境为 winxp jsdk1.4 log4j1.3 数据库是mysql

解决方案 »

  1.   

    #
    # This defines the logging level for the rootLogger. It is not required
    # if you are going to keep the level at debug as the rootLogger by default 
    # is at the debug level. The value after the comma is the appender for the
    # root and we have given it the name R
    #
    log4j.rootLogger=debug, R#
    # Since we plan to log to a database, we tell log4j that we will use the
    # JDBCAppender. To complete the configuration for this, we need to tell
    # some basic things to this appender. Database, Username, password and the
    # actual values to log. %m represents the message that will be generated by
    # our log statements.
    #
    log4j.appender.R=org.apache.log4j.jdbc.JDBCAppender
    #数据库连接串
    log4j.appender.R.URL=jdbc:mysql://localhost/test
    log4j.appender.R.user=root
    log4j.appender.R.password=
    log4j.appender.R.sql=INSERT INTO messages (message) VALUES ('%d - %c - %p - %m')#
    # These definea the layout to be used.
    #
    log4j.appender.R.layout=org.apache.log4j.PatternLayout上面是log4j的配置文件的内容。你要在数据库中建立一个messages表,表中有message字段。