Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2667

"Values not bound to statement" when using JDBC appender, appender does not respect bufferSize="0".

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.11.2, 2.12.0
    • 3.0.0, 2.13.1
    • Appenders, Core
    • None
    • Oracle Java 11.0.3, Windows Server 2016, Spring Boot 2.1.6

    Description

       

      Since version 2.11.2, the log4j2 library was unable to log message on database via JDBC connection. When using 2.11.1, no such problem was found. 

      root cause: 

      In org.sqlite.core.CorePreparedStatement, below function was called, but paramValid local variable is not initialized. Value of "paramValid.cardinality()" is always 0 which does not match with the total number of parameter.

       

      protected void checkParameters() throws SQLException
      { 
        if (paramValid.cardinality() != paramCount) 
          throw new SQLException("Values not bound to statement"); 
      }
      

       

      Sample appender in log4j2.xml

      <JDBC name="jdbcAppender" tableName="LOG_TABLE" bufferSize="0">
        <ConnectionFactory class="MY.SQLiteConnectionFactory" method="getDatabaseConnection" />
        <ColumnMapping name="FIELD1" type="java.lang.Integer" pattern="%X{FIELD1}" />
        <ColumnMapping name="FIELD2" type="java.lang.String" pattern="%X{FIELD2}" />
        <ColumnMapping name="FIELD3" type="java.lang.String" pattern="%X{FIELD3}" />
        <ColumnMapping name="FIELD4" type="java.sql.Types.TIMESTAMP" pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}" />
      </JDBC>

       

      Exception Log

      2019-08-02 15:57:45,483 main ERROR An exception occurred processing Appender jdbcAppender org.apache.logging.log4j.core.appender.db.DbAppenderLoggingException: Failed to commit transaction logging event or flushing buffer.
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.commitAndClose(JdbcDatabaseManager.java:552)
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeThrough(JdbcDatabaseManager.java:867)
      at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.write(AbstractDatabaseManager.java:264)
      at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.append(AbstractDatabaseAppender.java:110)
      at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
      at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:464)
      at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:448)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:431)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
      at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
      at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
      at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2170)
      at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2125)
      at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2108)
      at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2007)
      at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1866)
      at org.apache.logging.slf4j.Log4jLogger.info(Log4jLogger.java:179)
      ...
      Caused by: java.sql.SQLException: Values not bound to statement
      at org.sqlite.core.CorePreparedStatement.checkParameters(CorePreparedStatement.java:71)
      at org.sqlite.core.CorePreparedStatement.executeBatch(CorePreparedStatement.java:83)
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.commitAndClose(JdbcDatabaseManager.java:545)
      ...

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            ggregory Gary D. Gregory
            epmchui Edith Chui
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment