Make delicious recipes!

Formatting SQL Queries

Say you have some SQL queries that you want to execute.
Further these queries are generated at runtime and you want to log them.
If you just log the SQL strings, it would be pretty difficult to read them later on.
Hibernate has a nice utility here (which is internally used by Hibernate too) to format any SQL.

To format any insert/update/get query (like Hibernate), use the following:

For DML queries, use the following:

The FormatStyle class can be found in:
package org.hibernate.engine.jdbc.internal;

Like us on Facebook to remain in touch
with the latest in technology and tutorials!

Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Email: (Your email is not shared with anybody)

Facebook comments:

Site Owner: Sachin Goyal