SQL parser library for Java

Thilo picture Thilo · Mar 19, 2009 · Viewed 97k times · Source

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)

Answer

duffymo picture duffymo · Mar 19, 2009

ANTLR3 has an ANSI SQL grammar available. You can use that to create your own parser.

ANTLR4 has a SQL grammar.