aspose file tools
The moose likes Java in General and the fly likes Parse SQL Query using java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Parse SQL Query using java" Watch "Parse SQL Query using java" New topic
Author

Parse SQL Query using java

mani nataraj
Greenhorn

Joined: Dec 20, 2010
Posts: 12
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

Joined: Oct 27, 2005
Posts: 19216

ZQL is an SQL parser for Java.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6

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.


Never ascribe to malice that which can be adequately explained by stupidity.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35256
    
    7
I bet at least one of the standard Java parser packages (Antlr, JavaCC, SableCC) comes with a predefined grammar for SQL.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parse SQL Query using java
 
Similar Threads
dynamic help
Resultset with million rows
apply query after concate two column
Hibernate Query with AND condition
Named Query...