mybatis打印sql语句 请教下mybatis 如何打印sql语句 logs.properties 已经设置为debug了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 google一查全是ibatis的!唉…… mybatis -ibatis去掉ibatis嘛 mybatis 山寨? 不是的!是ibatis升级 贴上我的log4j.properties#logger level default is INFOlog4j.rootLogger=info,console,file#append to consolelog4j.appender.console=org.apache.log4j.ConsoleAppenderlog4j.appender.console.layout=org.apache.log4j.PatternLayoutlog4j.appender.console.layout.ConversionPattern=%d %p - %m%n#append to filelog4j.appender.file=org.apache.log4j.RollingFileAppenderlog4j.appender.file.File=/demo.loglog4j.appender.file.MaxFileSize=1MBlog4j.appender.file.MaxBackupIndex=10000log4j.appender.file.layout=org.apache.log4j.PatternLayoutlog4j.appender.file.layout.ConversionPattern=%d %p - %m%n#ibatis logger configlog4j.logger.com.ibatis=debuglog4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debuglog4j.logger.com.ibatis.common.jdbc.ScriptRunner=debuglog4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debuglog4j.logger.java.sql.Connection=debuglog4j.logger.java.sql.Statement=debuglog4j.logger.java.sql.PreparedStatement=debug,stdout这个是ibatis的大印sql 不知道mbatis行不行 试试 谢谢回复!ibatis我之前有用,就是用mybatis来替换之后就不能打印了! info 换成debug 试试一般debug信息里肯定会有sql语句以及相关事务 mybatis其实就是ibatis的更高版本而已,你就直接搜ibatis的,应该有帮助,最好去查文档,ibatis用的人也不是很多,mybatis还算比较新,估计用的人更少了 MyBatis自己内部使用的是Log4j,但实际上支持用户使用各种Log技术。如果配置正确的话,也就是启用debug级别即可打印所有的MyBatis的语句。比如,在我的web程序中,使用logback,maven依赖如下: <!--log-begin--> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.6.1</version> <scope>runtime</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>0.9.27</version> </dependency> <!--log-end-->src/main/resources/logback.xml文件内如下配置:<?xml version="1.0" encoding="UTF-8"?><configuration> <appender name="File" class="ch.qos.logback.core.FileAppender"> <file>/home/chenshu/webt.log</file> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> </layout> </appender> <logger name="com.base22" level="TRACE"/> <root level="debug"> <appender-ref ref="STDOUT" /> <appender-ref ref="File" /> </root></configuration> 关于MyBatis的使用,你最好加入MyBatis的邮件组,用英文提问,总会有人帮助你。据我所知,MyBatis的邮件组是总有很多人非常热心的,及时的回复。我也在其中。是我遇到的开源社区里面最活跃的邮件组。 我的程序打印出来的日志:10:30:16.741 [http-thread-pool-8080-(1)] DEBUG o.a.i.d.pooled.PooledDataSource - Checked out connection 30051965 from pool.10:30:16.741 [http-thread-pool-8080-(1)] DEBUG o.a.i.d.pooled.PooledDataSource - Testing connection 30051965 ...10:30:16.743 [http-thread-pool-8080-(1)] DEBUG o.a.i.d.pooled.PooledDataSource - Connection 30051965 is GOOD!10:30:16.743 [http-thread-pool-8080-(1)] DEBUG java.sql.Connection - ooo Connection Opened10:30:16.744 [http-thread-pool-8080-(1)] INFO com.webt.user.UserManager - session:false10:30:16.745 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Executing: select count(*) as FailedTimes from LoginHistory where (FailedName=?) and (Time between ? and ?) and (Result=1) 10:30:16.746 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Parameters: kaimei(String), 2011-01-14 10:30:16.744(Timestamp), 2011-01-15 10:30:16.744(Timestamp)10:30:16.747 [http-thread-pool-8080-(1)] DEBUG java.sql.ResultSet - <== Columns: FailedTimes10:30:16.747 [http-thread-pool-8080-(1)] DEBUG java.sql.ResultSet - <== Row: 010:30:16.748 [http-thread-pool-8080-(1)] INFO com.webt.user.SystemAdminManager - we are here10:30:16.748 [http-thread-pool-8080-(1)] INFO com.webt.user.UserManager - isAdministrator10:30:16.749 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Executing: select PersonID,PasswordHashValue,Salt,Phone,Address,Sex from Administrator where Name = ? or Email = ? 10:30:16.749 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Parameters: kaimei(String), null10:30:16.752 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Executing: select PersonID,PasswordHashValue,Salt,Name,Email,Phone,Address,Sex from User where Name = ? or Email = ? 10:30:16.752 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Parameters: kaimei(String), null10:30:16.754 [http-thread-pool-8080-(1)] DEBUG java.sql.ResultSet - <== Columns: PersonID, PasswordHashValue, Salt, Name, Email, Phone, Address, Sex10:30:16.754 [http-thread-pool-8080-(1)] DEBUG java.sql.ResultSet - <== Row: 1, 88e9e1390aacb14be605ee67850dfe945afec728f5703221e988eef31faf4520, 3jwd6giu, kaimei, [email protected], null, null, male 应该是在你的lib中有其他的日志jar包,把那些包删除掉试试 <!-- 显示sql --><logger name="java.sql"> <level value="debug" /></logger> # Rules reminder:# DEBUG < INFO < WARN < ERROR < FATALlog4j.logger.org.apache.ibatis=debug,stdout log4j.logger.java.sql=debug,stdout# My logging configuration...## Console output...log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%5p %d %C: %m%n @sheismylife 这个写的应该是对的 配置structs的时候报错 不知道是不是Myeclipse的问题 log4j日志问题(要求每天生成一日志。每天日志大于1mb就生成一个新的) JAVA Web编程中Oracle SQL的调优及表、索引的设计和优化 servlet 求一个SQL语句 hibernate初学者弱弱的问2 base64.求助。。 在Firefox里执行JAVA控件时的错误 为了搞计算机的兄弟的健康,请知道的提供信息,谢谢! 请教高手 hibernate主键生成策略native问题 哪位解释一下JAVA里面的连等式是什么意思???
去掉ibatis嘛
log4j.rootLogger=info,console,file#append to console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %p - %m%n#append to file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/demo.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 %p - %m%n
#ibatis logger config
log4j.logger.com.ibatis=debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug
log4j.logger.java.sql.Connection=debug
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=debug,stdout这个是ibatis的大印sql 不知道mbatis行不行 试试
一般debug信息里肯定会有sql语句以及相关事务
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.27</version>
</dependency>
<!--log-end-->
src/main/resources/logback.xml文件内如下配置:<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="File" class="ch.qos.logback.core.FileAppender">
<file>/home/chenshu/webt.log</file>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<logger name="com.base22" level="TRACE"/>
<root level="debug">
<appender-ref ref="STDOUT" />
<appender-ref ref="File" />
</root>
</configuration>
10:30:16.741 [http-thread-pool-8080-(1)] DEBUG o.a.i.d.pooled.PooledDataSource - Checked out connection 30051965 from pool.
10:30:16.741 [http-thread-pool-8080-(1)] DEBUG o.a.i.d.pooled.PooledDataSource - Testing connection 30051965 ...
10:30:16.743 [http-thread-pool-8080-(1)] DEBUG o.a.i.d.pooled.PooledDataSource - Connection 30051965 is GOOD!
10:30:16.743 [http-thread-pool-8080-(1)] DEBUG java.sql.Connection - ooo Connection Opened
10:30:16.744 [http-thread-pool-8080-(1)] INFO com.webt.user.UserManager - session:false
10:30:16.745 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Executing: select count(*) as FailedTimes from LoginHistory where (FailedName=?) and (Time between ? and ?) and (Result=1)
10:30:16.746 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Parameters: kaimei(String), 2011-01-14 10:30:16.744(Timestamp), 2011-01-15 10:30:16.744(Timestamp)
10:30:16.747 [http-thread-pool-8080-(1)] DEBUG java.sql.ResultSet - <== Columns: FailedTimes
10:30:16.747 [http-thread-pool-8080-(1)] DEBUG java.sql.ResultSet - <== Row: 0
10:30:16.748 [http-thread-pool-8080-(1)] INFO com.webt.user.SystemAdminManager - we are here
10:30:16.748 [http-thread-pool-8080-(1)] INFO com.webt.user.UserManager - isAdministrator
10:30:16.749 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Executing: select PersonID,PasswordHashValue,Salt,Phone,Address,Sex from Administrator where Name = ? or Email = ?
10:30:16.749 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Parameters: kaimei(String), null
10:30:16.752 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Executing: select PersonID,PasswordHashValue,Salt,Name,Email,Phone,Address,Sex from User where Name = ? or Email = ?
10:30:16.752 [http-thread-pool-8080-(1)] DEBUG java.sql.PreparedStatement - ==> Parameters: kaimei(String), null
10:30:16.754 [http-thread-pool-8080-(1)] DEBUG java.sql.ResultSet - <== Columns: PersonID, PasswordHashValue, Salt, Name, Email, Phone, Address, Sex
10:30:16.754 [http-thread-pool-8080-(1)] DEBUG java.sql.ResultSet - <== Row: 1, 88e9e1390aacb14be605ee67850dfe945afec728f5703221e988eef31faf4520, 3jwd6giu, kaimei, [email protected], null, null, male
<logger name="java.sql">
<level value="debug" />
</logger>
# DEBUG < INFO < WARN < ERROR < FATALlog4j.logger.org.apache.ibatis=debug,stdout
log4j.logger.java.sql=debug,stdout# My logging configuration...## Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p %d %C: %m%n