Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot show sql parameter binding?

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 the configuration as

spring.jpa.show-sql: true 
like image 244
Bhupati Patel Avatar asked Jun 17 '15 11:06

Bhupati Patel


2 Answers

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
like image 99
rv.comm Avatar answered Nov 18 '22 20:11

rv.comm


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/

like image 15
Alan Hay Avatar answered Nov 18 '22 20:11

Alan Hay