https://github.com/manticore-projects/jsqlformatter
Java SQL Formatter, Beautifier and Pretty Printer
https://github.com/manticore-projects/jsqlformatter
beautify formatter java mssql mysql oracle postgres pretty-print sql
Last synced: about 1 month ago
JSON representation
Java SQL Formatter, Beautifier and Pretty Printer
- Host: GitHub
- URL: https://github.com/manticore-projects/jsqlformatter
- Owner: manticore-projects
- License: other
- Created: 2021-04-09T03:10:31.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-08-05T07:19:38.000Z (2 months ago)
- Last Synced: 2025-08-07T01:48:53.409Z (2 months ago)
- Topics: beautify, formatter, java, mssql, mysql, oracle, postgres, pretty-print, sql
- Language: PLpgSQL
- Homepage: https://manticore-projects.com/JSQLFormatter/index.html
- Size: 5.95 MB
- Stars: 34
- Watchers: 1
- Forks: 7
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# manticore JSQLFormatter
Java SQL Formatter, Beautifier and Pretty Printer. Please visit our [Website](http://manticore-projects.com/JSQLFormatter/index.html) and try the [ONLINE Demo](http://jsqlformatter.manticore-projects.com).[](https://github.com/manticore-projects/jsqlformatter/actions/workflows/gradle.yml)
[](https://mvnrepository.com/artifact/com.manticore-projects.jsqlformatter/jsqlformatter)
[](https://app.codacy.com/gh/manticore-projects/jsqlformatter/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[](https://coveralls.io/github/manticore-projects/jsqlformatter)
[](#LICENSE)
[](https://github.com/manticore-projects/jsqlformatter/issues)
[](http://makeapullrequest.com)
## Features
* Based on [JSQLParser](https://github.com/JSQLParser/JSqlParser)
* Supports complex SELECT, INSERT INTO, MERGE, UPDATE, DELETE, CREATE, ALTER statements
* RDBMS agnostic and compatible to
* ANSI syntax highlighting
* Formatting Options for Indent Width, Comma Before or After, Upper/Lower/Camel Case spelling
* Import from Java String or StringBuilder, while preserving variables
* Export to Java String, StringBuilder or MessageFormat, while handling parameters
* Command Line Option (CLI) and SQL Inline Options```shell
java -jar JSQLFormatter.jar [-i ] [-o ] [-f |
--ansi | --html] [-t | -2 | -8] [--keywordSpelling ]
[--functionSpelling ] [--objectSpelling ] [--separation
] [--squareBracketQuotation ]-i,--inputFile The input SQL file or folder.
-o,--outputFile The out SQL file for the formatted
statements.
-f,--outputFormat The output-format.
[PLAIN* ANSI HTML RTF]
--ansi Output ANSI annotated text.
--html Output HTML annotated text.
-t,--indent The indent width.
[2 4* 8]
-2 Indent with 2 characters.
-8 Indent with 8 characters.
--keywordSpelling Keyword spelling.
[UPPER*, LOWER, CAMEL, KEEP]
--functionSpelling Function name spelling.
[UPPER, LOWER, CAMEL*, KEEP]
--objectSpelling Object name spelling.
[UPPER, LOWER*, CAMEL, KEEP]
--separation Position of the field separator.
[BEFORE*, AFTER]
--squareBracketQuotation Position of the field separator.
[AUTO*, YES, NO]
```* simple usage of the Java library
```java
import com.manticore.jsqlformatter.JSQLFormatter;
...
String formattedSql = JSQLFormatter.format("SELECT * FROM table1")
```with Maven Artifact:
```xml
com.manticore-projects.jsqlformatter
jsqlformatter
4.8.0
```## Samples
### Inline Formatting Options
```sql
-- @JSQLFormatter(indentWidth=8, keywordSpelling=UPPER, functionSpelling=CAMEL, objectSpelling=LOWER, separation=BEFORE)
UPDATE cfe.calendar
SET year_offset = ? /* year offset */
, settlement_shift = To_Char( ? ) /* settlement shift */
, friday_is_holiday = ? /* friday is a holiday */
, saturday_is_holiday = ? /* saturday is a holiday */
, sunday_is_holiday = ? /* sunday is a holiday */
WHERE id_calendar = ?
;-- @JSQLFormatter(indentWidth=2, keywordSpelling=LOWER, functionSpelling=KEEP, objectSpelling=UPPER, separation=AFTER)
update CFE.CALENDAR
set YEAR_OFFSET = ? /* year offset */,
SETTLEMENT_SHIFT = to_char( ? ) /* settlement shift */,
FRIDAY_IS_HOLIDAY = ? /* friday is a holiday */,
SATURDAY_IS_HOLIDAY = ? /* saturday is a holiday */,
SUNDAY_IS_HOLIDAY = ? /* sunday is a holiday */
where ID_CALENDAR = ?
;
```### Complex Comments
```sql
-- UPDATE CALENDAR
UPDATE cfe.calendar
SET year_offset = ? /* year offset */
, settlement_shift = ? /* settlement shift */
, friday_is_holiday = ? /* friday is a holiday */
, saturday_is_holiday = ? /* saturday is a holiday */
, sunday_is_holiday = ? /* sunday is a holiday */
WHERE id_calendar = ?
;-- BOTH CLAUSES PRESENT 'with a string' AND "a field"
MERGE /*+ PARALLEL */ INTO test1 /*the target table*/ a
USING all_objects /*the source table*/
ON ( /*joins in()!*/ a.object_id = b.object_id )
-- INSERT CLAUSE
WHEN /*comments between keywords!*/ NOT MATCHED THEN
INSERT ( object_id /*ID Column*/
, status /*Status Column*/ )
VALUES ( b.object_id
, b.status )
/* UPDATE CLAUSE
WITH A WHERE CONDITION */
WHEN MATCHED THEN /* Lets rock */
UPDATE SET a.status = '/*this is no comment!*/ and -- this ain''t either'
WHERE b."--status" != 'VALID'
;
```[More Samples](http://manticore-projects.com/JSQLFormatter/samples.html)