[ 
https://issues.apache.org/jira/browse/LOG4J2-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Brian Yeh resolved LOG4J2-2558.
-------------------------------
       Resolution: Fixed
    Fix Version/s: 2.11.2

> Literal values do not work with ColumnMapping for JdbcAppender
> --------------------------------------------------------------
>
>                 Key: LOG4J2-2558
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2558
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders, JDBC
>    Affects Versions: 2.11.1
>         Environment: MacOS High Sierra 10.13.6 Darwin Kernel Version 17.7.0
> java.vm.specification.version: 1.8
> os.arch: x86_64
>            Reporter: Brian Yeh
>            Priority: Major
>              Labels: Appender
>             Fix For: 2.11.2
>
>
> I'm programmatically updating the configuration after it has been created
>  
>  
> {code:java}
> final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
> final Configuration config = ctx.getConfiguration();
> ColumnConfig[] columnConfig = new ColumnConfig[0];
> ColumnMapping[] columnMappings = new ColumnMapping[1];
> columnMappings[0] = ColumnMapping.newBuilder()
>         .setLiteral("'TEST_STRING'")
>         .build();
> FactoryMethodConnectionSource myConnectionSource =
>         FactoryMethodConnectionSource.createConnectionSource(
>                 "com.ConnectionFactory",
>                 "getConnection");
> Appender appender = 
> org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender.newBuilder()
>         .setTableName("MSG_LOG")
>         .setConfiguration(config)
>         .setColumnMappings(columnMappings)
>         .setColumnConfigs(columnConfig)
>         .setConnectionSource(myConnectionSource)
>         .withName("db-appender")
>         .build();
> appender.start();
> config.addAppender(appender);
> Map<String, LoggerConfig> loggers = config.getLoggers();
> loggers.forEach((loggerName, loggerConfig) -> {
>     loggerConfig.addAppender(appender, org.apache.logging.log4j.Level.INFO, 
> null);
>     config.addLogger("org.apache.logging.log4j", loggerConfig);
> });
> ctx.updateLoggers();
> {code}
> Creates JdbcDatabaseManager with sqlStatement
>  
>  
> {code:java}
> INSERT INTO MSG_LOG (null) VALUES ('TEST_STRING'?)
> {code}
> As you can see, PARAMETER_MARKER "?" gets added.
>  
>  
> Later in writeInternal method, there is a check for layout without an else 
> condition
> {code:java}
> if (layout != null) //line 164 of JdbcDatabaseManager
> {code}
> Layout is null for my column so the parameter never get's set for the 
> PreparedStatement which will throw an error
> {code:java}
> Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 1
> at 
> oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2086)
> at 
> oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:9713)
> at 
> oracle.jdbc.driver.OraclePreparedStatementWrapper.addBatch(OraclePreparedStatementWrapper.java:1067)
> at 
> com.zaxxer.hikari.pool.HikariProxyPreparedStatement.addBatch(HikariProxyPreparedStatement.java)
> at 
> org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:199)
> ... 65 more
> {code}
> So, we could create the sqlStatement without the ParameterMarker "?" or 
> perhaps just make sure it gets set to null.
>  
> I would be open to making a PR if this is an issue and other can reproduce.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to