I need to parse sql statements and get column names and table names. I tried with sample code. I got table names but I am stucked to get column names for each table.
If you really really need to do this then you should look at using a proper parser toolkit like ANTLR. It is quite a steep learning curve but there are grammars around for SQL that others have already built.
Hand-cranking your own parser will lead you down a mess of bugs for anything but the most basic of queries.