项目中的SQL语句报错,有时实在不太明显,也没有能够记录执行时间的,所以找到log4jdbc,但是,配置项太多,输出格式不合要求,log4j2集成无法输出日志还是比较头大。今天把源码看了遍,部分地方作了修改。将代码提交此处,方便管理。
log4jdbc项目使用SLF4J 日志,该日志是一个接口,实现有很多种。
本项目中使用log4j2来桥接slf4j的日志,即log4jback的日志了。
#log4jdbc源码 代码基于log4jdbc开源项目
https://code.google.com/archive/p/log4jdbc/
https://github.com/arthurblake/log4jdbc
#log4jdbc概念 可参阅:http://blog.csdn.net/ycpanda/article/details/46519941
#url和driver配置示例 spring.datasource.driver-class-name=net.sf.log4jdbc.DriverSpy spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF8&characterSetResults=UTF8&autoReconnect=true&zeroDateTimeBehavior=convertToNull
#最佳实践:
###1.log4j.log4jdbc.properties 可以不用
###2.本例配合slf4j+log4j2使用,依赖如下 :
pom配置如下:
<slf4j.version>1.7.14</slf4j.version>
<log4j2.version>2.6.2</log4j2.version>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
log4j2.xml配置如下 :
<configuration status="WARN" monitorInterval="30" strict="true">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" ignoreExceptions="false">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %c{36}- %msg%n" />
</Console>
</Appenders>
<loggers>
<!--log4jdbc -->
<logger name="jdbc.sqlonly" level="OFF" additivity="false" />
<logger name="jdbc.resultset" level="OFF" additivity="false" />
<logger name="jdbc.connection" level="OFF" additivity="false" />
<logger name="jdbc.audit" level="OFF" additivity="false" />
<!-- <logger name="log4jdbc.debug" level="INFO" additivity="false" >
<appender-ref ref="Console" />
</logger>
<logger name="jdbc.sqltiming" level="INFO" additivity="false" >
<appender-ref ref="Console" />
</logger> -->
<!--默认的root的logger -->
<root level="debug">
<appender-ref ref="Console" />
</root>
</loggers>
</configuration>
###3.相对源码的修改部分 ++ 添加[SQL-CONFIG] 与[SQL] 等特殊字符来明显化这是一条sql操作相关日志
22:09:15.626 DEBUG log4jdbc.debug- [SQL-CONFIG]: FOUND DRIVER com.mysql.jdbc.Driver
++ 去掉原日志中的回车符号,让日志尽量在一行打印完毕
++ 添加数据库连接信息 (connection:1,e0a1828) ,1为第几个连接,e0a1828为java.sql.Connection对象的hascode的hex值,以此来标示并发时connection的全生命的日志
22:09:17.120 DEBUG jdbc.sqltiming- [SQL]:(connection:5,6f9bc97){update test_curd set name = '更新后的值' where id >= 0 }USE:108ms
###4.实践 #####只打印SQL及执行时间
<root level="debug">或者<root level="info">
#####打印SQL及connection的审计类(ConnectionPreparedStatement)信息
<root level="debug">或者<root level="info">
#####关闭SQL打印
###5.示例日志如下
22:09:15.617 DEBUG log4jdbc.debug- [SQL-CONFIG]:... log4jdbc initializing ...
22:09:15.618 DEBUG log4jdbc.debug- [SQL-CONFIG]: log4jdbc.properties not found on classpath
22:09:15.618 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.debug.stack.prefix is not defined
22:09:15.618 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.sqltiming.warn.threshold is not defined
22:09:15.618 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.sqltiming.error.threshold is not defined
22:09:15.618 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.booleanastruefalse is not defined (using default value false)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.maxlinelength is not defined (using default of 200)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.fulldebugstacktrace is not defined (using default value false)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.statement.warn is not defined (using default value false)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.select is not defined (using default value true)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.insert is not defined (using default value true)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.update is not defined (using default value true)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.delete is not defined (using default value true)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.create is not defined (using default value true)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.dump.sql.addsemicolon is not defined (using default value false)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.auto.load.popular.drivers is not defined (using default value true)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.trim.sql is not defined (using default value true)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.trim.sql.extrablanklines is not defined (using default value true)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.suppress.generated.keys.exception is not defined (using default value false)
22:09:15.619 DEBUG log4jdbc.debug- [SQL-CONFIG]:log4jdbc.drivers is not defined
22:09:15.626 DEBUG log4jdbc.debug- [SQL-CONFIG]: FOUND DRIVER com.mysql.jdbc.Driver
22:09:15.628 DEBUG log4jdbc.debug- [SQL-CONFIG]:... log4jdbc initialized! ...
22:09:15.785 INFO jdbc.connection- [SQL]:(connection:1,3aa82b22). Connection opened java.sql.DriverManager.getConnection(null:-1)
22:09:15.785 DEBUG jdbc.connection- [SQL]:open connections: 1 (1)
22:09:15.785 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). Connection.new Connection returned java.sql.DriverManager.getConnection(null:-1)
22:09:15.798 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.new PreparedStatement returned org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:15.799 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). Connection.prepareStatement(drop table if exists test_curd) returned net.sf.log4jdbc.PreparedStatementSpy@7cd569b5 org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:15.800 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@2b64ff3b org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:15.800 DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488) (connection:1,3aa82b22). drop table if exists test_curd
22:09:15.990 DEBUG jdbc.sqltiming- [SQL]:(connection:1,3aa82b22){drop table if exists test_curd }USE:190ms
22:09:15.991 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.executeUpdate() returned 0 org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488)
22:09:15.992 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
22:09:15.993 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.new PreparedStatement returned org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:15.993 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). Connection.prepareStatement(CREATE TABLE `test_curd` ( `id` int(11) NOT NULL AUTO_INCREMENT, `create_date` datetime DEFAULT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;) returned net.sf.log4jdbc.PreparedStatementSpy@7d380be8 org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:15.994 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@6a95ec91 org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:15.994 DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488) (connection:1,3aa82b22). CREATE TABLE `test_curd` ( `id` int(11) NOT NULL AUTO_INCREMENT, `create_date` datetime DEFAULT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
22:09:16.741 DEBUG jdbc.sqltiming- [SQL]:(connection:1,3aa82b22){CREATE TABLE `test_curd` ( `id` int(11) NOT NULL AUTO_INCREMENT, `create_date` datetime DEFAULT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; }USE:747ms
22:09:16.742 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.executeUpdate() returned 0 org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488)
22:09:16.742 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). PreparedStatement.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
清理表
22:09:16.743 INFO jdbc.connection- [SQL]:(connection:1,3aa82b22). Connection closed org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.743 DEBUG jdbc.connection- [SQL]:open connections: none
22:09:16.743 DEBUG jdbc.audit- [SQL]:(connection:1,3aa82b22). Connection.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.758 INFO jdbc.connection- [SQL]:(connection:2,6e9637fe). Connection opened java.sql.DriverManager.getConnection(null:-1)
22:09:16.758 DEBUG jdbc.connection- [SQL]:open connections: 2 (1)
22:09:16.758 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). Connection.new Connection returned java.sql.DriverManager.getConnection(null:-1)
22:09:16.761 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.new PreparedStatement returned org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:604)
22:09:16.761 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). Connection.prepareStatement(insert into test_curd(name,create_date) values(?,?), 1) returned net.sf.log4jdbc.PreparedStatementSpy@7deb27fa org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:604)
22:09:16.762 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@598dceab org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:16.762 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.setObject(1, 测试中文) returned org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.775 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.setObject(2, Sat Apr 29 22:09:16 CST 2017) returned org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.775 DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:606) (connection:2,6e9637fe). insert into test_curd(name,create_date) values('测试中文','2017-04-29 22:09:16')
22:09:16.856 DEBUG jdbc.sqltiming- [SQL]:(connection:2,6e9637fe){insert into test_curd(name,create_date) values('测试中文','2017-04-29 22:09:16') }USE:80ms
22:09:16.856 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.executeUpdate() returned 1 org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:606)
22:09:16.871 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@5cfc2617 org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.872 DEBUG jdbc.resultset- [SQL]:(connection:2,5cfc2617). ResultSet.new ResultSet returned org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.872 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getGeneratedKeys() returned net.sf.log4jdbc.ResultSetSpy@2e28dfb2 org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.873 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@5cfc2617 org.apache.commons.dbutils.handlers.MapHandler.handle(MapHandler.java:73)
22:09:16.873 DEBUG jdbc.resultset- [SQL]:(connection:2,5cfc2617). ResultSet.next() returned true org.apache.commons.dbutils.handlers.MapHandler.handle(MapHandler.java:73)
22:09:16.876 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@5cfc2617 org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:161)
22:09:16.877 DEBUG jdbc.resultset- [SQL]:(connection:2,5cfc2617). ResultSet.getMetaData() returned com.mysql.jdbc.ResultSetMetaData@3c1a42fa - Field level information:
com.mysql.jdbc.Field@602349e9[catalog=null,tableName=,originalTableName=null,columnName=GENERATED_KEY,originalColumnName=null,mysqlType=-1( Unknown MySQL Type # -1),flags=, charsetIndex=0, charsetName=UTF8] org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:161)
22:09:16.878 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@5cfc2617 org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:169)
22:09:16.878 DEBUG jdbc.resultset- [SQL]:(connection:2,5cfc2617). ResultSet.getObject(1) returned 1 org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:169)
22:09:16.879 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). PreparedStatement.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
insertTest: {GENERATED_KEY=1}
insertTest: null
22:09:16.881 INFO jdbc.connection- [SQL]:(connection:2,6e9637fe). Connection closed org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.881 DEBUG jdbc.connection- [SQL]:open connections: none
22:09:16.882 DEBUG jdbc.audit- [SQL]:(connection:2,6e9637fe). Connection.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.905 INFO jdbc.connection- [SQL]:(connection:3,454d427a). Connection opened java.sql.DriverManager.getConnection(null:-1)
22:09:16.905 DEBUG jdbc.connection- [SQL]:open connections: 3 (1)
22:09:16.905 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). Connection.new Connection returned java.sql.DriverManager.getConnection(null:-1)
22:09:16.906 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.new PreparedStatement returned org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:604)
22:09:16.906 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). Connection.prepareStatement(insert into test_curd(name,create_date) values(?,?), 1) returned net.sf.log4jdbc.PreparedStatementSpy@79e4de3d org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:604)
22:09:16.906 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@20bab550 org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:16.906 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.setObject(1, 测试中文) returned org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.907 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.setObject(2, Sat Apr 29 22:09:16 CST 2017) returned org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.907 DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:606) (connection:3,454d427a). insert into test_curd(name,create_date) values('测试中文','2017-04-29 22:09:16')
22:09:16.986 DEBUG jdbc.sqltiming- [SQL]:(connection:3,454d427a){insert into test_curd(name,create_date) values('测试中文','2017-04-29 22:09:16') }USE:79ms
22:09:16.987 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.executeUpdate() returned 1 org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:606)
22:09:16.987 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@3206ee33 org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.987 DEBUG jdbc.resultset- [SQL]:(connection:3,3206ee33). ResultSet.new ResultSet returned org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.987 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getGeneratedKeys() returned net.sf.log4jdbc.ResultSetSpy@65006fed org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:607)
22:09:16.987 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@3206ee33 org.apache.commons.dbutils.handlers.MapHandler.handle(MapHandler.java:73)
22:09:16.988 DEBUG jdbc.resultset- [SQL]:(connection:3,3206ee33). ResultSet.next() returned true org.apache.commons.dbutils.handlers.MapHandler.handle(MapHandler.java:73)
22:09:16.988 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@3206ee33 org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:161)
22:09:16.988 DEBUG jdbc.resultset- [SQL]:(connection:3,3206ee33). ResultSet.getMetaData() returned com.mysql.jdbc.ResultSetMetaData@7fb46468 - Field level information:
com.mysql.jdbc.Field@1c2c2958[catalog=null,tableName=,originalTableName=null,columnName=GENERATED_KEY,originalColumnName=null,mysqlType=-1( Unknown MySQL Type # -1),flags=, charsetIndex=0, charsetName=UTF8] org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:161)
22:09:16.988 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@3206ee33 org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:169)
22:09:16.988 DEBUG jdbc.resultset- [SQL]:(connection:3,3206ee33). ResultSet.getObject(1) returned 2 org.apache.commons.dbutils.BasicRowProcessor.toMap(BasicRowProcessor.java:169)
22:09:16.988 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). PreparedStatement.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
insertTest: {GENERATED_KEY=2}
insertTest: null
22:09:16.988 INFO jdbc.connection- [SQL]:(connection:3,454d427a). Connection closed org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.988 DEBUG jdbc.connection- [SQL]:open connections: none
22:09:16.988 DEBUG jdbc.audit- [SQL]:(connection:3,454d427a). Connection.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:16.998 INFO jdbc.connection- [SQL]:(connection:4,3bf06804). Connection opened java.sql.DriverManager.getConnection(null:-1)
22:09:16.998 DEBUG jdbc.connection- [SQL]:open connections: 4 (1)
22:09:16.998 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). Connection.new Connection returned java.sql.DriverManager.getConnection(null:-1)
22:09:16.998 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.new PreparedStatement returned org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:16.999 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). Connection.prepareStatement(select * from test_curd where id>?) returned net.sf.log4jdbc.PreparedStatementSpy@201d324c org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:16.999 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@5cd12c0c org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:16.999 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.setObject(1, 1) returned org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:16.999 DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347) (connection:4,3bf06804). select * from test_curd where id>1
22:09:16.999 DEBUG jdbc.sqltiming- [SQL]:(connection:4,3bf06804){select * from test_curd where id>1 }USE:0ms
22:09:16.999 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
22:09:16.999 DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.new ResultSet returned org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
22:09:17.000 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.executeQuery() returned net.sf.log4jdbc.ResultSetSpy@6322ad40 org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:347)
22:09:17.000 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f org.apache.commons.dbutils.handlers.ArrayHandler.handle(ArrayHandler.java:83)
22:09:17.000 DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.next() returned true org.apache.commons.dbutils.handlers.ArrayHandler.handle(ArrayHandler.java:83)
22:09:17.000 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:99)
22:09:17.000 DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.getMetaData() returned com.mysql.jdbc.ResultSetMetaData@799c7798 - Field level information:
com.mysql.jdbc.Field@f6fda88[catalog=test,tableName=test_curd,originalTableName=test_curd,columnName=id,originalColumnName=id,mysqlType=3(FIELD_TYPE_LONG),flags= AUTO_INCREMENT PRIMARY_KEY, charsetIndex=63, charsetName=US-ASCII]
com.mysql.jdbc.Field@78741ea2[catalog=test,tableName=test_curd,originalTableName=test_curd,columnName=create_date,originalColumnName=create_date,mysqlType=12(FIELD_TYPE_DATETIME),flags= BINARY, charsetIndex=63, charsetName=US-ASCII]
com.mysql.jdbc.Field@f875b76[catalog=test,tableName=test_curd,originalTableName=test_curd,columnName=name,originalColumnName=name,mysqlType=253(FIELD_TYPE_VAR_STRING),flags=, charsetIndex=33, charsetName=UTF-8] org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:99)
22:09:17.000 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.000 DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.getObject(1) returned 2 org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.000 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.000 DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.getObject(2) returned 2017-04-29 22:09:16.0 org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.000 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.001 DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.getObject(3) returned 测试中文 org.apache.commons.dbutils.BasicRowProcessor.toArray(BasicRowProcessor.java:104)
22:09:17.001 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.getConnection() returned net.sf.log4jdbc.ConnectionSpy@28a2f76f org.apache.commons.dbutils.DbUtils.close(DbUtils.java:72)
22:09:17.001 DEBUG jdbc.resultset- [SQL]:(connection:4,28a2f76f). ResultSet.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:72)
22:09:17.001 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). PreparedStatement.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
selectTest: [2, 2017-04-29 22:09:16.0, 测试中文]
22:09:17.001 INFO jdbc.connection- [SQL]:(connection:4,3bf06804). Connection closed org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:17.001 DEBUG jdbc.connection- [SQL]:open connections: none
22:09:17.001 DEBUG jdbc.audit- [SQL]:(connection:4,3bf06804). Connection.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:17.011 INFO jdbc.connection- [SQL]:(connection:5,6f9bc97). Connection opened java.sql.DriverManager.getConnection(null:-1)
22:09:17.011 DEBUG jdbc.connection- [SQL]:open connections: 5 (1)
22:09:17.011 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). Connection.new Connection returned java.sql.DriverManager.getConnection(null:-1)
22:09:17.011 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.new PreparedStatement returned org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:17.011 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). Connection.prepareStatement(update test_curd set name = ? where id >= ?) returned net.sf.log4jdbc.PreparedStatementSpy@3cf9a477 org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:17.012 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@299c9fe7 org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:17.012 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.setObject(1, 更新后的值) returned org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:17.012 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.setObject(2, 0) returned org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:17.012 DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488) (connection:5,6f9bc97). update test_curd set name = '更新后的值' where id >= 0
22:09:17.120 DEBUG jdbc.sqltiming- [SQL]:(connection:5,6f9bc97){update test_curd set name = '更新后的值' where id >= 0 }USE:108ms
22:09:17.120 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.executeUpdate() returned 2 org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488)
22:09:17.121 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). PreparedStatement.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
成功更新2条数据!
22:09:17.122 INFO jdbc.connection- [SQL]:(connection:5,6f9bc97). Connection closed org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:17.122 DEBUG jdbc.connection- [SQL]:open connections: none
22:09:17.122 DEBUG jdbc.audit- [SQL]:(connection:5,6f9bc97). Connection.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:17.163 INFO jdbc.connection- [SQL]:(connection:6,85132f5). Connection opened java.sql.DriverManager.getConnection(null:-1)
22:09:17.163 DEBUG jdbc.connection- [SQL]:open connections: 6 (1)
22:09:17.164 DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). Connection.new Connection returned java.sql.DriverManager.getConnection(null:-1)
22:09:17.164 DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.new PreparedStatement returned org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:17.164 DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). Connection.prepareStatement(DELETE from test_curd WHERE id = ?) returned net.sf.log4jdbc.PreparedStatementSpy@23e28c99 org.apache.commons.dbutils.AbstractQueryRunner.prepareStatement(AbstractQueryRunner.java:154)
22:09:17.164 DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.getParameterMetaData() returned com.mysql.jdbc.MysqlParameterMetadata@6e7ca336 org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:225)
22:09:17.165 DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.setObject(1, 0) returned org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:242)
22:09:17.165 DEBUG jdbc.sqlonly- [SQL]: org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488) (connection:6,85132f5). DELETE from test_curd WHERE id = 0
22:09:17.166 DEBUG jdbc.sqltiming- [SQL]:(connection:6,85132f5){DELETE from test_curd WHERE id = 0 }USE:0ms
22:09:17.166 DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.executeUpdate() returned 0 org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:488)
22:09:17.166 DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). PreparedStatement.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:84)
删除成功0条数据!
22:09:17.167 INFO jdbc.connection- [SQL]:(connection:6,85132f5). Connection closed org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
22:09:17.167 DEBUG jdbc.connection- [SQL]:open connections: none
22:09:17.167 DEBUG jdbc.audit- [SQL]:(connection:6,85132f5). Connection.close() returned org.apache.commons.dbutils.DbUtils.close(DbUtils.java:60)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型