Repolode
JSQLParser

JSQLParser/JSqlParser

A Java SQL parser that turns SQL statements into a traversable tree of Java objects and can render them back to SQL text.

Stars
5,975
Forks
1,446
Open issues
8
Last commit
2 days ago

What is it?

JSqlParser parses an SQL statement into a hierarchy of Java classes that can be navigated with the Visitor pattern, rewritten, and printed back as SQL. It is RDBMS-agnostic: one grammar covers dialects such as MySQL, PostgreSQL, Oracle, SQL Server, BigQuery, Snowflake, DuckDB and SQLite, with dialect options for edge cases.

Beyond parsing, the project can classify a statement by whether it returns rows or modifies data, which helps build read-only guards or choose between query and update execution. Statements can also be built from Java with a fluent API and serialized to SQL text. Piped SQL syntax is in progress.

It requires a JDK 11 runtime and is distributed through Maven Central, with the actively maintained Manticore builds recommended over the older upstream release.

Key features

  • 01Parses SQL into a Java object tree that can be traversed with the Visitor pattern
  • 02Converts the object model back into SQL text
  • 03Covers many dialects including MySQL, PostgreSQL, Oracle, SQL Server and BigQuery
  • 04Classifies statements by whether they return rows or modify data
  • 05Builds SQL statements from Java with a fluent API

Use cases

  • Rewriting or auditing SQL queries in a Java application before execution
  • Blocking data-modifying statements on read-only database connections
  • Extracting tables and columns referenced by a query for analysis or lineage tooling
  • Generating SQL programmatically from Java code

Quick start

  1. 1

    Add the Manticore build dependency to your Maven pom.xml

  2. 2

    Parse a SQL statement with CCJSqlParserUtil.parse and walk the resulting tree

Things to know

  • Building from source requires a JDK 17 toolchain.
  • The README recommends Manticore builds because the upstream Maven Central release is considerably older.

In collections

Topics

#sql#parser#java#ast#database#sql-parser#visitor-pattern#hierarchy#jsqlparser#mysql

FAQ

What is JSqlParser?
A Java SQL parser that turns SQL statements into a traversable tree of Java objects and can render them back to SQL text. JSqlParser parses an SQL statement into a hierarchy of Java classes that can be navigated with the Visitor pattern, rewritten, and printed back as SQL. It is RDBMS-agnostic: one grammar covers dialects such as MySQL, PostgreSQL, Oracle, SQL Server, BigQuery, Snowflake, DuckDB and SQLite, with dialect options for edge cases.
Is JSqlParser free to use? What license does it have?
JSqlParser is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is JSqlParser still maintained?
Actively maintained. The last commit to JSqlParser was on Nov 5, 2026.
What can I use JSqlParser for?
Rewriting or auditing SQL queries in a Java application before execution Blocking data-modifying statements on read-only database connections Extracting tables and columns referenced by a query for analysis or lineage tooling Generating SQL programmatically from Java code
How do I install JSqlParser?
Add the Manticore build dependency to your Maven pom.xml Parse a SQL statement with CCJSqlParserUtil.parse and walk the resulting tree
Where can I get JSqlParser?
The source code and installation instructions are on GitHub: https://github.com/JSQLParser/JSqlParser

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects

Free browser-based database schema editor that draws ER diagrams and generates SQL scripts, with no account required.

Developer Tools#database-design#erd#sql
40.3K+77 this week3.4KJavaScriptAGPL-3.0Well maintainedUpdated 23 hours ago