如何使用JDBC创建存储过程?我已经尝试了以下代码,但它失败并出现错误。
' sql'的内容在jdbc代码中使用的变量
CREATE PROCEDURE 'init'()
BEGIN
DECLARE '_rollback' BOOL DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET '_rollback' = 1;
START TRANSACTION;
DROP TABLE IF EXISTS tst;
CREATE TABLE IF NOT EXISTS tst
(
did INT AUTO_INCREMENT PRIMARY KEY,
stage INT
);
INSERT INTO tst (stage) VALUES (11);
INSERT INTO tst (stage) VALUES (23);
IF '_rollback'
THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
END;
JDBC代码:
Statement statement = connection.createStatement();
statement.executeLargeUpdate(sql);
JDBC错误:
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''create_and_populate_schema'()
BEGIN
DECLARE '_rollback' BOOL DEFAULT 0;
' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:536)
我希望DELIMITER不应该被设置,因为它只适用于' mysql'客户端似乎没有任何替代sql-String应该与JDBC一起使用