log4j2 JDBC Appender问题:无法插入记录

时间:2014-06-16 10:58:24

标签: java logging jdbc log4j log4j2

我创建了一个JDBC appender并绑定了ColumnConfig和DataSourceConnectionSource。

尝试在DB中插入记录时(Logger.debug(“Test”))。我的异常低于。

由于

[6/16/14 18:44:58:647 GMT-08:00] 00000024 SystemErr     R ERROR StatusLogger An exception occurred processing Appender JDBCAppender org.apache.logging.log4j.core.appender.AppenderLoggingException: Failed to insert record for log event in JDBC manager: DSRA1300E: Feature is not implemented: PreparedStatement.setNString
    at org.apache.logging.log4j.core.appender.db.jdbc.JDBCDatabaseManager.writeInternal(JDBCDatabaseManager.java:117)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.write(AbstractDatabaseManager.java:159)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.append(AbstractDatabaseAppender.java:103)
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:97)
    at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:425)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
    at org.apache.logging.log4j.core.Logger$PrivateConfig.logEvent(Logger.java:275)
    at org.apache.logging.log4j.core.async.AsyncLogger.actualAsyncLog(AsyncLogger.java:289)
    at org.apache.logging.log4j.core.async.RingBufferLogEvent.execute(RingBufferLogEvent.java:99)
    at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:43)
    at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:28)
    at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.sql.SQLFeatureNotSupportedException: DSRA1300E: Feature is not implemented: PreparedStatement.setNString
    at com.ibm.ws.rsadapter.AdapterUtil.notSupportedX(AdapterUtil.java:1306)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.setNString(WSJdbcPreparedStatement.java:2362)
    at org.apache.logging.log4j.core.appender.db.jdbc.JDBCDatabaseManager.writeInternal(JDBCDatabaseManager.java:104)
    ... 14 more
Caused by: java.lang.AbstractMethodError: java/sql/PreparedStatement.setNString(ILjava/lang/String;)V
    at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.setNString(WSJdbcPreparedStatement.java:2346)
    ... 15 more

1 个答案:

答案 0 :(得分:7)

我之前的回答是不正确的,道歉。 可以修改此行为by configuration。默认情况下,所有列(isEventTimestamp="true"除外)都被视为unicode字符串,并通过PreparedStatement.setNString方法插入值。如果您使用isUnicode="false"配置列,则会通过PreparedStatement.setString插入值,这应该有效。列配置示例:

  <Appenders>
    <JDBC name="databaseAppender" tableName="dbo.application_log">
      <DataSource jndiName="java:/comp/env/jdbc/LoggingDataSource" />
      <Column name="eventDate" isEventTimestamp="true" />
      <Column name="level" pattern="%level" isUnicode="false" />
      <Column name="logger" pattern="%logger" isUnicode="false" />
      <Column name="message" pattern="%message" isUnicode="false" />
      <Column name="exception" pattern="%ex{full}" isUnicode="false" />
    </JDBC>
  </Appenders>