SQL parser library for Java [closed]
Is there an open-source Java library for parsing SQL statements?
If possible, it should be customizable or flexible enough to also be able to parse (or at least ignore) vendor-specific syntax (such as Oracle tablespace definitions or MySQL's LIMIT clause).
If not, strict adherence to the SQL standard is also fine.
Update: I need this for two things:
- providing an SQL interface to a non-SQL database (mapping to internal API calls)
- rewriting SQL before it goes to the actual database (e.g. Oracle)
Solution 1:
ANTLR3 has an ANSI SQL grammar available. You can use that to create your own parser.
ANTLR4 has a SQL grammar.
Solution 2:
- JSqlParser
- Presto's parser is written using ANTLR4 and has its own immutable AST classes that are built from the parser. The AST has a visitor and pretty printer.