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.
What you need is an SQL parser.
You can try JSQLParser, or ZQL.
I have used both successfully for the same thing the you are trying to do.
You can try also sqlparser. This is commercial however and I have no experience using it.