1.Http://log4jdbc.googlecode.com/files/log4jdbc4-1.2.jar
Http://www.slf4j.org/download.html
Download Log4jdbc4-1.2.jar,Slf4j-api-1.7.5.jar, Slf4j-log4j12-1.7.5.jar three jar packages.
2. Modify the JDBC configuration file
< Bean id="DataSource"
class="Org.apache.commons.dbcp.BasicDataSource" destroy-method="Close" >
< Property name="Driverclassname" value="net.sf.log4jdbc.DriverSpy"/>
< Property name="url" value="jdbc:log4jdbc:mysql://localhost:3306/atpco"/ >
< Property name="username" value="${username}"/>
< Property name="password" ref="Ddns_password" />
</ Bean >
driverclassname modified to net.sf.log4jdbc.DriverSpy
The URL is based on the original JDBC: Changed to JDBC:LOG4JDBC: (add prefix 'log4jdbc: ')
3. Modify the log4j.properties configuration file
Add the following code to the original base:
#For JDBC
# Root Logger option
log4j.logger.jdbc.audit=INFO, file
Log4j.additivity.jdbc.audit=True
log4j.logger.jdbc.sqltiming=INFO, file
Log4j.additivity.jdbc.sqltiming=True
log4j.logger.jdbc.connection=INFO, file
Log4j.additivity.jdbc.connection=True
log4j.logger.jdbc.resultset=Fatal,file
Log4j.additivity.jdbc.resultset=false
log4j.logger.jdbc.sqlonly=Fatal,file
Log4j.additivity.jdbc.sqlonly=false
# Direct log messages to a log file
log4j.appender.file=Org.apache.log4j.RollingFileAppender
log4j.appender.file.file=C:/logs/log4jdbc.log
log4j.appender.file.maxfilesize=1MB
log4j.appender.file.maxbackupindex=10000
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.conversionpattern=%d{yyyy-mm-dd HH:mm:ss} %- 5p %c{1}:%l - %m%n
About the use of LOG4JDBC production SQL statements