Does someone have pretty_print function for print SQL query in java?
given string like:
SELECT person_table.name FROM person_table JOIN person_person ON person_table.name=person_person WHERE person_table.name=dan
The function will print:
SELECT person_table.name
FROM person_table
JOIN person_person
ON person_table.name=person_person
WHERE person_table.name=dan
or better?
Thanks in advance!
String sql = pretty. select( AUTHOR. LAST_NAME, count().
All SQL statements in pureQuery code are embedded in quotation marks. The SQL statements are formatted by keyword and indentation. Each SQL keyword starts on a new line. To remain consistent with Eclipse Java formatting, after the SQL is separated into multiple lines, each string is embedded in quotation marks.
With the file with the extension sql open, select "Format SQL" from the Edit menu. With the file with the extension sql open, select "Format SQL" from the context menu of the editor. Use Ctrl + Shift + L on Windows, Cmd + Shift + L on OS X to format currently active document.
You can take a look at org.apache.openjpa.lib.jdbc.SQLFormatter.
If you work with Hibernate try org.hibernate.jdbc.util.FormatStyle.BASIC.getFormatter().format(yourNonFormattedSqlQueryString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With