MySQL错误"'字段列表中的未知列'"

时间:2017-04-27 10:05:33

标签: mysql jdbc

我有以下SQL命令:

CREATE PROCEDURE aiContract 
    ( IN pStudent VARCHAR(63), IN pStartDate BIGINT, IN pEndDate BIGINT, 
        IN pAdvisor VARCHAR(255), IN pResearchGroup INTEGER, IN pProject VARCHAR(255), 
        IN pWage DOUBLE, IN pHours INTEGER, IN pLastConfirmation BIGINT, OUT newId INT )
    begin 
        SELECT COALESCE(MAX(ID), -1) + 1 INTO newId FROM contract; 
        INSERT INTO contract 
            VALUES(newId, pStudent, pStartDate, pEndDate, pAdvisor, pResearchGroup, pProject, pWage, pHours, pLastConfirmation); 
    end;

一旦它完全正常工作但现在我得到以下错误:

ERROR 1064 (42000): 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 '' at line 1

ERROR 1054 (42S22): Unknown column 'newId' in 'field list'

ERROR 1064 (42000): 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 'end' at line 1

我使用JDBC执行此命令。这是java代码:

List<String> sqls6 = new LinkedList<>();
                sqls6.add("delimiter //");
                sqls6.add("CREATE PROCEDURE aiContract "
                        + "( IN pStudent VARCHAR(63), IN pStartDate BIGINT, IN pEndDate BIGINT, "
                        + "IN pAdvisor VARCHAR(255), IN pResearchGroup INTEGER, IN pProject VARCHAR(255), "
                        + "IN pWage DOUBLE, IN pHours INTEGER, IN pLastConfirmation BIGINT, OUT newId INT ) "
                        + "begin SELECT COALESCE(MAX(ID), -1) + 1 INTO newId "
                        + "FROM contract; INSERT INTO contract VALUES(newId, pStudent, pStartDate, pEndDate, "
                        + "pAdvisor, pResearchGroup, pProject, pWage, pHours, pLastConfirmation); end//");
                sqls6.add("delimiter ;");
                sqls6.add("ALTER TABLE contract CHANGE ID ID INTEGER;");

                Statement stmt6 = null;
                for (int i = 0; i < sqls6.size(); i++) {

                    try {
                        stmt6 = getStatement();
                        stmt6.execute(sqls6.get(i));
                    } catch (SQLException e) {
                        e.printStackTrace();
                    } finally {
                        // closing statement [...]
                    }
                }

为什么呢? :(

编辑: 我没有改变任何东西(至少我不能说什么),但它突然起作用了。无法分辨这里的问题。

1 个答案:

答案 0 :(得分:0)

如果您在mysql中创建,那么您可能忘记设置分隔符

drop procedure if exists aicontract;
delimiter // 
CREATE PROCEDURE aiContract 
    ( IN pStudent VARCHAR(63), IN pStartDate BIGINT, IN pEndDate BIGINT, 
        IN pAdvisor VARCHAR(255), IN pResearchGroup INTEGER, IN pProject VARCHAR(255), 
        IN pWage DOUBLE, IN pHours INTEGER, IN pLastConfirmation BIGINT, OUT newId INT )
    begin 
        SELECT COALESCE(MAX(ID), -1) + 1 INTO newId FROM contract; 
        INSERT INTO contract 
            VALUES(newId, pStudent, pStartDate, pEndDate, pAdvisor, pResearchGroup, pProject, pWage, pHours, pLastConfirmation); 
    end //

delimiter ;