“set”是reserve word in Mysql,所以可能是你的问题。一般建议是避免保留字词并有意义地命名您的程序(例如 setAccountRecrod)。
当我设法使用该名称创建过程时,我必须使用转义名称(带有反勾号)调用它:
stmt.executeQuery("call `set`("+id+",'"+name+"','"+sal+"','"+dept+"')");
但按照建议,最好像这样使用prepareCall:
callableStatement = dbConnection.prepareCall("call `set`(" + id + ",'" +
name + "','" + sal + "','" + dept + "')");
callableStatement.executeUpdate();
甚至更好:
callableStatement = dbConnection.prepareCall("call `set`(?,?,?,?)");
callableStatement.setInt(1, id);
callableStatement.setString(2, name);
callableStatement.setString(3, sal);
callableStatement.setString(4, dept);
callableStatement.executeUpdate();
当我创建这样的程序时,以上所有内容都适用于最新版本的 MariaDb:
DELIMITER $$
DROP PROCEDURE IF EXISTS `set`;
CREATE PROCEDURE `set` (IN id INT, name VARCHAR(25), sal VARCHAR(25), dept VARCHAR(25))
BEGIN
SELECT VERSION();
END $$
DELIMITER ;