Description
The JDBC Appender fails when using both parameter, {{source, and literal in ColumnMapping elements.
Example configuration fragment:
<Jdbc name="MySQL-Response" tableName="${sys:test.TABLE_PROP_NAME}" ignoreExceptions="false"> <DriverManager connectionString="jdbc:mysql://localhost:3306/mydb?useSSL=false&verifyServerCertificate=false&jdbcCompliantTruncation=false" userName="${sys:mysql.userName}" password="${sys:mysql.password}"/> <ColumnMapping name="version" /> <ColumnMapping name="proxy_id" source="proxyId" /> <ColumnMapping name="config_id" source="configId" /> <ColumnMapping name="api_key" source="apiKey"/> <ColumnMapping name="uuid" /> <ColumnMapping name="instant" parameter="TIMESTAMP(FROM_UNIXTIME(?/1000))"/> <ColumnMapping name="durationSeconds" /> <ColumnMapping name="durationNano" /> <ColumnMapping name="durationMillis" /> <ColumnMapping name="origin_local_address" source="origin_localAddress" /> <ColumnMapping name="origin_local_port" source="origin_localPort" /> <ColumnMapping name="origin_remote_address" source="origin_remoteAddress" /> <ColumnMapping name="origin_remote_port" source="origin_remotePort" /> <ColumnMapping name="origin_socket_timeout" source="origin_socketTimeout" /> <ColumnMapping name="origin_server_name" source="originServer_name" /> <ColumnMapping name="origin_server_uri" source="originServer_uri" /> <ColumnMapping name="protocol_name" source="httpResponse_protocolVersion_protocol" /> <ColumnMapping name="protocol_major" source="httpResponse_protocolVersion_major" /> <ColumnMapping name="protocol_minor" source="httpResponse_protocolVersion_minor" /> <ColumnMapping name="header_connection" source="httpResponse_headers_Connection" /> <ColumnMapping name="header_content_length" source="httpResponse_headers_Content_Length" /> <ColumnMapping name="header_content_type" source="httpResponse_headers_Content_Type" /> <ColumnMapping name="header_date" source="httpResponse_headers_Date" /> <ColumnMapping name="header_server" source="httpResponse_headers_Server" /> <ColumnMapping name="status_code" source="httpResponse_statusCode" /> <ColumnMapping name="reason_phrase" literal="'012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'" /> <MessageLayout /> </Jdbc>
Example failure:
2018-11-15 15:38:22,238 requester-dispatch-1 ERROR Unable to write to database [JdbcManager{name=MySQL-Response, bufferSize=0, tableName=API_RESPONSE_02dcb136_3a95_4900_b6bb_3efb8d1c882b, columnConfigs=[], columnMappings=[ColumnMapping [name=version, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=proxy_id, source=proxyId, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=config_id, source=configId, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=api_key, source=apiKey, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=uuid, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=instant, source=null, literalValue=null, parameter=TIMESTAMP(FROM_UNIXTIME(?/1000)), type=class java.lang.String, layout=null], ColumnMapping [name=durationSeconds, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=durationNano, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=durationMillis, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=origin_local_address, source=origin_localAddress, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=origin_local_port, source=origin_localPort, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=origin_remote_address, source=origin_remoteAddress, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=origin_remote_port, source=origin_remotePort, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=origin_socket_timeout, source=origin_socketTimeout, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=origin_server_name, source=originServer_name, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=origin_server_uri, source=originServer_uri, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=protocol_name, source=httpResponse_protocolVersion_protocol, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=protocol_major, source=httpResponse_protocolVersion_major, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=protocol_minor, source=httpResponse_protocolVersion_minor, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=header_connection, source=httpResponse_headers_Connection, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=header_content_length, source=httpResponse_headers_Content_Length, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=header_content_type, source=httpResponse_headers_Content_Type, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=header_date, source=httpResponse_headers_Date, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=header_server, source=httpResponse_headers_Server, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=status_code, source=httpResponse_statusCode, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=reason_phrase, source=null, literalValue='012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789', parameter=null, type=class java.lang.String, layout=null]]}] for appender [MySQL-Response]. org.apache.logging.log4j.core.appender.db.DbAppenderLoggingException: Failed to insert record for log event in JDBC manager: Parameter index out of range (26 > number of parameters, which is 25). at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:579) at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeThrough(JdbcDatabaseManager.java:604) 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.logIfEnabled(AbstractLogger.java:1827) at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1281) ... Caused by: java.sql.SQLException: Parameter index out of range (26 > number of parameters, which is 25). at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) at com.mysql.cj.jdbc.ClientPreparedStatement.checkBounds(ClientPreparedStatement.java:1406) at com.mysql.cj.jdbc.ClientPreparedStatement.getCoreParameterIndex(ClientPreparedStatement.java:1419) at com.mysql.cj.jdbc.ClientPreparedStatement.setObject(ClientPreparedStatement.java:1703) at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.setFields(JdbcDatabaseManager.java:493) at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:524) ... 35 more 2018-11-15 15:38:22,244 requester-dispatch-1 ERROR An exception occurred processing Appender MySQL-Response org.apache.logging.log4j.core.appender.db.DbAppenderLoggingException: Failed to insert record for log event in JDBC manager: Parameter index out of range (26 > number of parameters, which is 25). at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:579) at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeThrough(JdbcDatabaseManager.java:604) 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.logIfEnabled(AbstractLogger.java:1827) at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1281) ... Caused by: java.sql.SQLException: Parameter index out of range (26 > number of parameters, which is 25). at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) at com.mysql.cj.jdbc.ClientPreparedStatement.checkBounds(ClientPreparedStatement.java:1406) at com.mysql.cj.jdbc.ClientPreparedStatement.getCoreParameterIndex(ClientPreparedStatement.java:1419) at com.mysql.cj.jdbc.ClientPreparedStatement.setObject(ClientPreparedStatement.java:1703) at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.setFields(JdbcDatabaseManager.java:493) at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:524) ... 35 more