Java SQL Parser Library

GitGub Release Badge GitGub Issues Badge Maven Badge Maven Build Status Coverage Status Codacy Status Java Docs

JSQLParser is a SQL statement parser built from JavaCC. It translates SQLs in a traversable hierarchy of Java classes. The upcoming 5.0 release will depend on Java 11 and introduces new Visitors. Please see the Migration to 5.0 guide.

Latest stable release: JSQLFormatter-4.5.jar

Development version: JSQLFormatter-4.6-SNAPSHOT.jar

Sample SQL Statement
SELECT /*+ PARALLEL */
    cfe.id_collateral_ref.nextval
    , id_collateral
FROM (  SELECT DISTINCT
            a.id_collateral
        FROM cfe.collateral a
            LEFT JOIN cfe.collateral_ref b
                ON a.id_collateral = b.id_collateral
        WHERE b.id_collateral_ref IS NULL )
;

SQL Dialects

JSqlParser is RDBMS agnostic and provides support for many dialects such as:

  • Oracle Database

  • MS SqlServer

  • MySQL and MariaDB

  • PostgreSQL

  • H2

Features

  • Comprehensive support for statements:
    • QUERY: SELECT ...

    • DML: INSERT ... INTO ... UPDATE ... MERGE ... INTO ... DELETE ... FROM ...

    • DDL: CREATE ... ALTER ... DROP ...

  • Nested Expressions (e.g. Sub-Selects)

  • WITH clauses

  • Old Oracle JOIN (+)

  • PostgreSQL implicit CAST ::

  • SQL Parameters (e.g. ? or :parameter)

  • Arrays vs. T-SQL Squared Bracket Quotes

  • Fluent API to create SQL Statements from java Code

  • Statement De-Parser to write SQL from Java Objects