通过JSQLParser解析sql语句里面的table

jsqlparser是github上一个开源项目,maven的配置如下:


com.github.jsqlparser
jsqlparser
1.1


publicList tablesNameBysql() {

String sql ="select * from Outvisit l left join patient p on l.patid=p.patientid join patstatic c on  l.patid=c.patid inner join patphone  ph  on l.patid=ph.patid where l.name='kevin'  union all select * from invisit v";

Statement statement = CCJSqlParserUtil.parse(sql);

//            Select selectStatement = (Select)statement;

TablesNamesFinder tablesNamesFinder =newTablesNamesFinder();

List result = tablesNamesFinder.getTableList(statement);

for(String tableStr:result){

logger.debug(">>>> "+ tableStr);

}

return result;

}


>>>> Outvisit

>>>> patient

>>>> patstatic

>>>> patphone

>>>> invisit

你可能感兴趣的:(通过JSQLParser解析sql语句里面的table)