Spring boot show sql parameter binding?

2020-07-06 02:18发布

I am new to spring boot. What is the configuration setting for sql parameter binding. For example in the following line I should be able to see values for all '?'.

SELECT * FROM MyFeed WHERE feedId > ? AND isHidden = false ORDER BY feedId DESC LIMIT ?

Currently I have configuration as

spring.jpa.show-sql: true

4条回答
Viruses.
2楼-- · 2020-07-06 02:40

Add these to the property file

#to show sql
spring.jpa.properties.hibernate.show_sql=true
#formatting
spring.jpa.properties.hibernate.format_sql=true
#printing parameter values in order
logging.level.org.hibernate.type.descriptor.sql=trace
查看更多
一纸荒年 Trace。
3楼-- · 2020-07-06 02:46

Add these to application.properties and you should see the logs in details.

logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
查看更多
太酷不给撩
4楼-- · 2020-07-06 02:52

This is just a hint to the underlying persistence provider e.g. Hibernate, EclipseLink etc. Without knowing what you are using it is difficult to say.

For Hibernate you can configure logging to also output the bind parameters:

http://www.mkyong.com/hibernate/how-to-display-hibernate-sql-parameter-values-log4j/

which will give you output like:

Hibernate: INSERT INTO transaction (A, B) 
VALUES (?, ?)
13:33:07,253 DEBUG FloatType:133 - binding '10.0' to parameter: 1
13:33:07,253 DEBUG FloatType:133 - binding '1.1' to parameter: 2

An alternative solution which should work across all JPA providers is to use something like log4jdbc which would give you the nicer output:

INSERT INTO transaction (A, B) values (10.0, 1.1);

See:

https://code.google.com/p/log4jdbc-log4j2/

查看更多
对你真心纯属浪费
5楼-- · 2020-07-06 02:59

For Eclipse link, Add these lines in appilication.properties

jpa.eclipselink.showsql=true
jpa.eclipselink.logging-level=FINE
查看更多
登录 后发表回答