Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JavaDB as SQL parser

Tags:

java

sql

javadb

About a month ago I built an application that used zSQL as the SQL parser to parse SQL. However, just few days ago, a heavy duty user sent in a multi row insert statement which zSQL doesn't support. This is the sample:

INSERT INTO MyTable (FirstCol, SecondCol)
SELECT 'First' ,1
UNION ALL
SELECT 'Second' ,2
UNION ALL
SELECT 'Third' ,3
UNION ALL
SELECT 'Fourth' ,4
UNION ALL
SELECT 'Fifth' ,5

Then I found this link: http://weblogs.java.net/blog/2008/11/23/stand-alone-sql-parser-java, it says "With a simple fix, Rick Hillegas has ensured that developers can have access to a powerful SQL parser that comes with Apache/Derby". However, I can't find any relevant documentation to achieve this.

Any idea?

like image 894
Reusable Avatar asked Oct 27 '25 08:10

Reusable


2 Answers

Did you try clicking on the link 'a simple fix' in that post on java.net? The first comment shows how to run the tool. If you read the code to ASTParser.java, you can see the code you need to write to use the parser.

like image 108
Tom Anderson Avatar answered Oct 28 '25 22:10

Tom Anderson


The link you have given uses Internal APIs of Derby, it also requires the debug version of Derby.

As of version 10.10, it still cannot be used as a general SQL Parser as it requires the tables in the SQL to exist - not a good sign that their parser is separate enough for use as a parser! (And in general a worrying sign that their architecture is crap)

like image 28
user1244215 Avatar answered Oct 28 '25 21:10

user1244215