I am using JSQLPARSER for the first time. I have some SQL files which come dynamically, i need to read table and column names from that SQL. After lot of googling I tried with JSQLPARSER. I am trying to read column names from the file but I am unable to read column names due to expression, please can any one correct my code where I went wrong. I am getting CLASSCASTEXCEPTION code:
public static void main(String[] args) throws JSQLParserException
{
// TODO Auto-generated method stub
String statement="SELECT LOCATION_D.REGION_NAME, LOCATION_D.AREA_NAME, COUNT(DISTINCT INCIDENT_FACT.TICKET_ID) FROM LOCATION_D, INCIDENT_FACT WHERE ( LOCATION_D.LOCATION_SK=INCIDENT_FACT.LOCATION_SK ) GROUP BY LOCATION_D.REGION_NAME, LOCATION_D.AREA_NAME";
CCJSqlParserManager parserManager = new CCJSqlParserManager();
Select select=(Select) parserManager.parse(new StringReader(statement));
PlainSelect plain=(PlainSelect)select.getSelectBody();
List selectitems=plain.getSelectItems();
System.out.println(selectitems.size());
for(int i=0;i<selectitems.size();i++)
{
Expression expression=((SelectExpressionItem) selectitems.get(i)).getExpression();
System.out.println("Expression:-"+expression);
Column col=(Column)expression;
System.out.println(col.getTable()+","+col.getColumnName());
}
}