java 解析sql语句中所有的表名称
maven依赖
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.3</version>
</dependency>
测试代码
/**
* @author chongmengzhao
* @version 0.1
* @date 2021/5/6 10:00
* @Description TODO
*/
import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
import com.alibaba.druid.util.JdbcConstants;
import java.util.List;
/**
* 基于Druid的sql解析功能,获取表名
*/
public class DruidUtil {
public static void main(String[] args) {
String sql = "select * from Outvisit l\n" +
"left join patient p on l.patid=p.patien