import java.io.StringReader;
import java.util.List;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitorAdapter;
import net.sf.jsqlparser.statement.create.procedure.CreateProcedure;
import net.sf.jsqlparser.statement.select.Select;
public class ParseProcedureExample {
public static void main(String[] args) throws JSQLParserException {
String sql = "CREATE PROCEDURE my_proc(IN param1 INT, OUT param2 INT)\n" +
"BEGIN\n" +
" SELECT * FROM my_table WHERE id = param1;\n" +
" UPDATE my_table SET value = 1 WHERE id = param1;\n" +
" SET param2 = 1;\n" +
"END";
Statement statement = CCJSqlParserUtil.parse(new StringReader(sql));
statement.accept(new StatementVisitorAdapter() {
@Override
public void visit(CreateProcedure createProcedure) {
System.out.println("Procedure name: " + createProcedure.getProcedureName());
System.out.println("Parameters: " + createProcedure.getParameters());
System.out.println("Body statements: " + createProcedure.getStatements());
}
@Override
public void visit(Select select) {
// Ignore SELECT statements
}
});
}
}
标签:jsqlparser,statement,test,import,net,createProcedure,sf From: https://www.cnblogs.com/wanglichaoya/p/17492736.html