不完整的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
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/q601115211/article/details/54588507