jsqlparser是github上一个开源项目,maven的配置如下:
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>1.1</version>
</dependency>
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