hibernate显示完整的sql

不完整的SQL

Hibernate: /* insert com.test.bean.User */ insert into user (username, password, email, sex) values (?, ?, ?, ?)

hibernate 显示的SQL语句不完整,调试程序非常不方便,我们需要改在完整显示的方式。
1.需要加入一个p6spy.jar包、spy.properties 配置文件。
spy.properties

realdriver=com.mysql.jdbc.Driver
#logfile=d:/sys.log
module.log=com.p6spy.engine.logging.P6LogFactory
appender=com.p6spy.engine.logging.appender.StdoutLogger
deregisterdrivers=true

2.修改 hibernate.cfg.xml 文件、
把com.mysql.jdbc.Driver修改成com.p6spy.engine.spy.P6SpyDriver

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!--url信息 -->
        <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
        <!--数据库方言信息 -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <!--用户名 -->
        <property name="connection.username">root</property>
        <!--密码 -->
        <property name="connection.password">123456</property>
        <!--数据库驱动信息 -->
        <!--<property name="connection.driver_class">com.mysql.jdbc.Driver</property>-->
        <property name="connection.driver_class">com.p6spy.engine.spy.P6SpyDriver</property>

        <!-- 是否显示sql   -->  
        <property name="show_sql">true</property>  
        <!-- 是否格式化sql -->  
        <property name="format_sql">false</property>  
        <!-- 是否使用注释  -->  
        <property name="use_sql_comments">true</property>  
        <!--指定Hibernate映射文件路径 -->
        <mapping resource="com/test/bean/User.hbm.xml" />
        <!-- <mapping class="com.test.bean.Test" /> -->
    </session-factory>
</hibernate-configuration> 

到这就可以显示完整的SQL了

1484663444061|-1||info

reloadProperties() successful
1484663444086|-1||info

deregistering driver com.mysql.jdbc.Driver
1484663444087|-1||debug

Registered driver: com.mysql.jdbc.Driver, realdriver: com.mysql.jdbc.Driver@7188af83
1484663444088|-1||debug

Registered factory: com.p6spy.engine.logging.P6LogFactory with options: null
1484663444088|-1||debug

Driver manager reporting driver registered: com.p6spy.engine.spy.P6SpyDriver@59402b8f
1484663444088|-1||debug

Driver manager reporting driver registered: com.mysql.jdbc.Driver@7188af83
一月 17, 2017 10:30:44 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.p6spy.engine.spy.P6SpyDriver] at URL [jdbc:mysql://localhost:3306/test]
一月 17, 2017 10:30:44 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
一月 17, 2017 10:30:44 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
一月 17, 2017 10:30:44 下午 org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
1484663444124|-1||debug

found new driver com.mysql.jdbc.Driver@7188af83
1484663444125|-1||debug

this is com.p6spy.engine.spy.P6SpyDriver@6f10d5b6 and passthru is com.mysql.jdbc.Driver@7188af83
一月 17, 2017 10:30:44 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
一月 17, 2017 10:30:44 下午 org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
Hibernate: /* insert com.test.bean.User */ insert into user (username, password, email, sex) values (?, ?, ?, ?)
1484663445964|2|0|statement
/* insert com.test.bean.User */ insert into user (username, password, email, sex) values (?, ?, ?, ?)
/* insert com.test.bean.User */ insert into user (username, password, email, sex) values ('6011XXXXXXX@qq.com', '123456', '6011XXXXXXX@qq.com', '1')
1484663445981|4|0|commit
  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值