我该如何修复错误?
log4j.properties
# Define the root logger with appender file
log4j.rootLogger = ALL, DB
# Define the DB appender
log4j.appender.DB=org.apache.log4j.jdbc.JDBCAppender
# Set JDBC URL
log4j.appender.DB.URL=jdbc:mysql://localhost/youtube
# Set Database Driver
log4j.appender.DB.driver=com.mysql.jdbc.Driver
# Set database user name and password
log4j.appender.DB.user=root
log4j.appender.DB.password=root
# Set the SQL statement to be executed.
log4j.appender.DB.sql=INSERT INTO logs VALUES('%x','%d','%C','%p','%m')
# Define the layout for file appender
log4j.appender.DB.layout=org.apache.log4j.PatternLayout
jdbcAppender.java
public class jdbcAppender{
/* Get actual class name to be printed on */
static Logger log = Logger.getLogger(jdbcAppender.class.getName());
public static void main(String[] args) throws IOException,SQLException{
log.debug("Debug");
log.info("Info");
}
}
数据库
错误
解决方法:
根据您使用的MySQL版本,您需要定义DATED字段,以便它可以接受包含一秒的分数的DATETIME值.默认情况下,DATETIME接受值为YY-MM-DDDD HH:MM:SS.
您可能遇到的另一个问题是,MySQL期望分数的分隔符是点(.),而不是逗号.您的异常堆栈跟踪显示逗号作为分隔符,我相信它是从您的系统的区域设置派生的.
标签:java,mysql,jdbc,log4j
来源: https://codeday.me/bug/20190529/1180767.html