import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.select.Select; import net.sf.jsqlparser.util.TablesNamesFinder; public class StoredProcParserExample { public static void main(String[] args) { String storedProcDefinition = "CREATE PROCEDURE `get_products`()\n" + "BEGIN\n" + " SELECT * FROM products WHERE price > 100;\n" + "END"; try { // 解析存储过程定义 Statement stmt = CCJSqlParserUtil.parse(storedProcDefinition); // 提取存储过程中的表名 TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); Select select = (Select) stmt; PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); plainSelect.accept(tablesNamesFinder); String[] tableNames = tablesNamesFinder.getTableList().toArray(new String[0]); // 打印表名 for (String tableName : tableNames) { System.out.println("Table: " + tableName); } } catch (Exception e) { e.printStackTrace(); } } }
标签:test2,String,jsqlparser,import,net,sf,select From: https://www.cnblogs.com/wanglichaoya/p/17495755.html