log4j:ERROR无法执行sql。 mysql在appender中插入问题

时间:2018-10-12 08:21:54

标签: java mysql logging log4j

我在使用log4j附加程序时遇到问题,该问题可能会登录到数据库。有我的appender

import org.apache.log4j.Logger;
import java.sql.*;
import java.io.*;


public class TestLogger
{
 /* Get actual class name to be printed on */
    public static final Logger log = 
    Logger.getLogger(TestLogger.class.getName());

    public static void main(String[] args)throws IOException,SQLException
    {
       log.debug("Debug");
       log.info("Info");
    }
    }

有我的主班

log4j:ERROR Failed to excute sql
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right 
syntax to use near 'Debug' at line 1
 at 
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118)
at 
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1393)
at com.mysql.cj.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2353)
at com.mysql.cj.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1303)
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.debug(Category.java:260)
at TestLogger.main(TestLogger.java:13)

我收到此错误。

declare @test table (ID int not null, P_ID int null, Qty int not null)
insert into @test(ID, P_ID, Qty) values
(1 , 11  , 1),
(2 , null, 3),
(11, 21  , 2),
(21, 31  , 1),
(31, null, 3),
(12, null, 4)

select
    COALESCE(T2.ID,T1.ID) as ID,
    MAX(CASE WHEN T1.P_ID is not null then T1.ID END) as OldID,     
    SUM(Qty) as Qty
from   
    @test T1
        left join
        (select ID from @test 
            GROUP By ID) T2
            on  T2.ID = T1.P_ID

group by
    COALESCE(T2.ID, T1.ID)

怎么了?我试图在mysql工作台中通过查询插入数据库,并且工作正常。我在这里https://www.tutorialspoint.com/log4j/log4j_logging_database.htm

0 个答案:

没有答案