使用MS SQL Server的Log4J JDBCAppender异常

时间:2016-08-15 04:42:11

标签: sql-server log4j

我使用以下代码来获取使用log4j的数据库记录器。

            PatternLayout layout = new PatternLayout();

            JDBCAppender jdbcAppender = new JDBCAppender();
            jdbcAppender.setDriver(jdbc);
            jdbcAppender.setUser(user);
            jdbcAppender.setPassword(password);
            jdbcAppender.setURL(url);
            jdbcAppender
                    .setSql("INSERT INTO " + logTable + " VALUES('%x', '%d', '%C', '%p', '%m')");
            jdbcAppender.setLayout(layout);
            jdbcAppender.activateOptions();

            Logger rootLogger = Logger.getRootLogger();
            rootLogger.setLevel(Level.DEBUG);
            rootLogger.addAppender(jdbcAppender);

            Logger logger = Logger.getLogger(type);

记录抛出异常: logger.info("This is log");

log4j:ERROR Failed to excute sql
java.sql.SQLException: Incorrect syntax near the keyword 'is'.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2988)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2421)
    at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:671)
    at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:613)
    at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:572)
    at net.sourceforge.jtds.jdbc.JtdsStatement.executeImpl(JtdsStatement.java:809)
    at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:1288)
    at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:1241)
    at org.apache.log4j.jdbc.JDBCAppender.execute(JDBCAppender.java:218)
    at org.apache.log4j.jdbc.JDBCAppender.flushBuffer(JDBCAppender.java:289)
    at org.apache.log4j.jdbc.JDBCAppender.append(JDBCAppender.java:186)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.info(Category.java:666)
    at com.nirvasoft.logging.Main.main(Main.java:20)

可能导致错误的原因是什么?

0 个答案:

没有答案