Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j2 JDBC Appender Issue:Failed to Insert Record

I have created a JDBC appender and bind the ColumnConfig and DataSourceConnectionSource .

while trying to insert record in the DB (Logger.debug("Test")).I am getting below exception.

Thanks

[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
like image 480
saurabh goyal Avatar asked Jun 16 '14 10:06

saurabh goyal


1 Answers

My previous answer was incorrect, apologies. It is possible to modify this behaviour by configuration. By default, all columns (except if isEventTimestamp="true") are treated as unicode strings and the value is inserted via the PreparedStatement.setNString method. If you configure your columns with isUnicode="false", values are inserted via the PreparedStatement.setString, which should work. Example column configuration:

  <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>
like image 124
Remko Popma Avatar answered Sep 21 '22 02:09

Remko Popma