不完整的SQL
Hibernate: 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>
<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.p6spy.engine.spy.P6SpyDriver</property>
<property name="show_sql">true</property>
<property name="format_sql">false</property>
<property name="use_sql_comments">true</property>
<mapping resource="com/test/bean/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
到这就可以显示完整的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:
一月 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 into user (username, password, email, sex) values (?, ?, ?, ?)
1484663445964|2|0|statement
insert into user (username, password, email, sex) values (?, ?, ?, ?)
insert into user (username, password, email, sex) values ('6011XXXXXXX@qq.com', '123456', '6011XXXXXXX@qq.com', '1')
1484663445981|4|0|commit
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41