views:

87

answers:

2

Hi,

Does anyone know about a SQL statements parser, in Java, that would allow having an Object representation of a SQL query, allow modifying this representation and generate back the updated SQL statement?

Regards, Christophe

+1  A: 

I would think that ANTLR would be able to do this.

Ira Baxter
I think so, but I was looking for a, let's say, simpler solution. With ANTLR, I still need to generate the parser on my own and actually, I did not find the information if the SQL ANSI grammar was compatible with the ANTLR v3. Not sure either that you can update the model and generate back the SQL string.
Christophe
I'm not deeply familiar with ANTLR. I'm pretty sure you can update the model. Regenerating the SQL string should be at worst straightforward tree walk-and-print, and ANTLR has something called "string templates" to help. Yes, you're likely to have do some work to get your result if you use ANTLR. You should ask at the ANTLR site.
Ira Baxter
A: 

Maybe you could look at JSqlParser.

Mark
I found that one as well. It is not very clear if you can change the SQL model and get back the rewritten SQL. Maybe to toString() will do the job.
Christophe