• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parse SQL Query using java  RSS feed

 
mani nataraj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

user create some sql query. In query contains selected coloumns,and aggregate functions etc. I need to separate selected coloumn using java.

For Ex: SELECT EMP_NAME,EMP_NO,EMP_ADDRESS,EMP_RELION,EMP_PINCODE,EMP_MOBILE,
DECODE(EMP_NAME,'TEST', EMP_NAME,EMP_NAME) from EMP;

I am trying to parse query using StringTokenizer using "," separator but not parse in properly

How to do this. Can you give me a solution for this.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ZQL is an SQL parser for Java.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to break it apart a piece at a time. First, break apart the string bases on the SQL keywords (like "select", "from", "where" "group by", "sort by", etc). Once you have everything that is between "select" and "from", you should be able to pick that apart by the commas.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I bet at least one of the standard Java parser packages (Antlr, JavaCC, SableCC) comes with a predefined grammar for SQL.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!