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:
FormatStyle.BASIC.getFormatter().format(sqlString)
For DML queries, use the following:
FormatStyle.DDL.getFormatter().format(sqlString)
The FormatStyle class can be found in:
package org.hibernate.engine.jdbc.internal;
|