Please visit the WebSite. JSqlParser is a RDBMS agnostic SQL statement parser. It translates SQL statements into a traversable hierarchy of Java classes (see Samples):
SELECT1FROM dual WHERE a = bSQL Text └─Statements: statement.select.PlainSelect ├─selectItems: statement.select.SelectItem │ └─LongValue: 1 ├─Table: dual └─where: expression.operators.relational.EqualsTo ├─Column: a └─Column: b StringsqlStr = "select 1 from dual where a=b"; PlainSelectselect = (PlainSelect) CCJSqlParserUtil.parse(sqlStr); SelectItemselectItem = select.getSelectItems().get(0); Assertions.assertEquals( newLongValue(1) , selectItem.getExpression()); Tabletable = (Table) select.getFromItem(); Assertions.assertEquals("dual", table.getName()); EqualsToequalsTo = (EqualsTo) select.getWhere(); Columna = (Column) equalsTo.getLeftExpression(); Columnb = (Column) equalsTo.getRightExpression(); Assertions.assertEquals("a", a.getColumnName()); Assertions.assertEquals("b", b.getColumnName())}JSqlParser aims to support the SQL standard as well as all major RDBMS. Any missing syntax or features can be added on demand.
| RDBMS | Statements |
|---|---|
| Oracle MS SQL Server and Sybase Postgres MySQL and MariaDB DB2 H2 and HSQLDB and Derby SQLite | SELECTINSERT, UPDATE, UPSERT, MERGEDELETE, TRUNCATE TABLECREATE ..., ALTER ...., DROP ...WITH ... |
JSqlParser can also be used to create SQL Statements from Java Code with a fluent API (see Samples).
General SQL Parser looks pretty good, with extended SQL syntax (like PL/SQL and T-SQL) and java + .NET APIs. The tool is commercial (license available online), with a free download option.
JSqlParser is dual licensed under LGPL V2.1 or Apache Software License, Version 2.0.