• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Parse SQL Query using java

 
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.
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ZQL is an SQL parser for Java.
 
lowercase baba
Posts: 12893
63
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.
 
Rancher
Posts: 43016
76
  • 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.
 
Hug your destiny! And hug this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic