12

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!

1
  • 3
    The thing with that is that everyone has a different way of writing SQL - some people place the JOIN clause on the same line as the FROM, or keep the ON clause with the JOIN clause on the same line. Commented Feb 28, 2013 at 16:52

2 Answers 2

4

You can take a look at org.apache.openjpa.lib.jdbc.SQLFormatter.

Sign up to request clarification or add additional context in comments.

Comments

3

If you work with Hibernate try org.hibernate.jdbc.util.FormatStyle.BASIC.getFormatter().format(yourNonFormattedSqlQueryString);

1 Comment

Works for HQL too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.