Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any java library to format SQL?

Tags:

java

I am looking for a simple library [free] wherein i can use something like this:-

String formattedSQL = xyzLib.format ( sql );

Is there any such library? Or is there a way to format the SQL?

like image 225
Rakesh Juyal Avatar asked Nov 18 '10 10:11

Rakesh Juyal


2 Answers

I'm not aware of a library that does this, but you might look at Hibernate's SQL formatter. From my experience it does a pretty good job at prettifying SQL statements, but as always, it might not be exactly what you want.

like image 107
darioo Avatar answered Oct 06 '22 01:10

darioo


Yohei Yamana (vertical-blank) has written an open source, pure-Java standalone, zero-dependencies SQL Formatter. It is available from maven central:

<dependency>
  <groupId>com.github.vertical-blank</groupId>
  <artifactId>sql-formatter</artifactId>
  <version>1.0</version>
</dependency>
like image 22
Choppy The Lumberjack Avatar answered Oct 06 '22 00:10

Choppy The Lumberjack