简体   繁体   中英

SQL Query parser for Java

I am looking for SQL query parser for MySQL queries. Using which I can parse the query, modify the query object and print back modified query

JSQL Parser was exactly what I needed but It has 2 main issues while escaping single quote inside column values https://github.com/JSQLParser/JSqlParser/issues/167 https://github.com/JSQLParser/JSqlParser/issues/166

So I am looking for open source alternative which can help me with the task

Presto-parser I tried was not able to parse Update queries

If anyone else is aware of any other reliable SQL Parsing library please let me know

Regarding JSqlParser :

Issue 166 already fixed.

The escaping of single quotes is not supported, but using double single quotes is. Therefore someone could replace all \\' using '' before parsing.

EDIT: Issue 167 fixed within actual Snapshot 0.9.5 of JSqlParser.

One year ago i search for the same thing but finally i use another approach. Those were the projects that i found to parse sql.

  • ANTLR . Is commonly used generic parser. It's a kind of parser generator. From a set of rules it writes the java code. There are rules for a lot of thins like spanish, java or sql.

  • JParsec . Seems similar to the previous one. Seems that already exists SQL rules, but does not seem easy to use.

  • ZQL . Uses JavaCC to auto-generate Java code that parses the SQL. I test this one but i can not get it working as i want. And i think that the project is discontinued.

  • sql-parser . It looks nice, but when i tested it i can not get it working. The link seems to not work, but i think that this is a fork of the original project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM