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.
Joined: Mar 22, 2005
I bet at least one of the standard Java parser packages (Antlr, JavaCC, SableCC) comes with a predefined grammar for SQL.