不完整的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了
|-||info reloadProperties() successful
|-||info deregistering driver com.mysql.jdbc.Driver
|-||debug Registered driver: com.mysql.jdbc.Driver, realdriver: com.mysql.jdbc.Driver@7188af83
|-||debug Registered factory: com.p6spy.engine.logging.P6LogFactory with options: null
|-||debug Driver manager reporting driver registered: com.p6spy.engine.spy.P6SpyDriver@59402b8f
|-||debug Driver manager reporting driver registered: com.mysql.jdbc.Driver@7188af83
一月 , :: 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.p6spy.engine.spy.P6SpyDriver] at URL [jdbc:mysql://localhost:3306/test]
一月 , :: 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
一月 , :: 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
一月 , :: 下午 org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: (min=)
|-||debug found new driver com.mysql.jdbc.Driver@7188af83
|-||debug this is com.p6spy.engine.spy.P6SpyDriver@6f10d5b6 and passthru is com.mysql.jdbc.Driver@7188af83
一月 , :: 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
一月 , :: 下午 org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [] less than
Hibernate: /* insert com.test.bean.User */ insert into user (username, password, email, sex) values (?, ?, ?, ?)
|||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', '', '6011XXXXXXX@qq.com', '')
|||commit
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.****.net/q601115211/article/details/54588507