存储过程问题,在本地运行但不在服务器上运行

发布于 2024-10-26 18:01:46 字数 1716 浏览 2 评论 0原文

我在使用 MySQL 存储过程时遇到了一个奇怪的问题。

我编写了一个简单的存储过程,如下所示:

{

    DELIMITER $$

    CREATE DEFINER=`username`@`%` PROCEDURE `sp_create_my_log`(IN source TEXT,
      OUT my_id INT)
    BEGIN
      --
      -- insert record and return primary key
      INSERT INTO my_log (source) VALUES (source);
      SET my_id = LAST_INSERT_ID();

      COMMIT;
    END
}

该存储过程在我的本地计算机(MySQL Server 5.1,Windows XP)上运行得非常好。但是当我尝试在服务器上运行它时,出现以下错误:

java.sql.SQLException: Parameter index of 2 is out of range (1, 0)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
    at com.mysql.jdbc.CallableStatement$CallableStatementParamInfo.checkBounds(CallableStatement.java:274)
    at com.mysql.jdbc.CallableStatement.checkParameterIndexBounds(CallableStatement.java:710)
    at com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java:672)
    at com.mysql.jdbc.CallableStatement.registerOutParameter(CallableStatement.java:1846)
    at org.apache.commons.dbcp.DelegatingCallableStatement.registerOutParameter(DelegatingCallableStatement.java:95)
    at org.apache.commons.dbcp.DelegatingCallableStatement.registerOutParameter(DelegatingCallableStatement.java:95)
    at com.mycomp.myprj.importer.ImporterImpl.onPreLoad(ImporterImpl.java:160)
    at com.mycomp.myprj.importer.csv.FileImporter.load(FileImporter.java:43)
    at com.mycomp.myprj.importer.csv.MyImporter.main(MyImporter.java:82)
0.843 seconds

知道为什么会发生这种情况吗?

I am having a strange problem with MySQL Stored Procedure.

I have written a simple stored procedure as follows:

{

    DELIMITER $

    CREATE DEFINER=`username`@`%` PROCEDURE `sp_create_my_log`(IN source TEXT,
      OUT my_id INT)
    BEGIN
      --
      -- insert record and return primary key
      INSERT INTO my_log (source) VALUES (source);
      SET my_id = LAST_INSERT_ID();

      COMMIT;
    END
}

This stored procedure is running absolutely fine on my local machine (MySQL Server 5.1, Windows XP). But when I try to run it on the server, I get the following error:

java.sql.SQLException: Parameter index of 2 is out of range (1, 0)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
    at com.mysql.jdbc.CallableStatement$CallableStatementParamInfo.checkBounds(CallableStatement.java:274)
    at com.mysql.jdbc.CallableStatement.checkParameterIndexBounds(CallableStatement.java:710)
    at com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java:672)
    at com.mysql.jdbc.CallableStatement.registerOutParameter(CallableStatement.java:1846)
    at org.apache.commons.dbcp.DelegatingCallableStatement.registerOutParameter(DelegatingCallableStatement.java:95)
    at org.apache.commons.dbcp.DelegatingCallableStatement.registerOutParameter(DelegatingCallableStatement.java:95)
    at com.mycomp.myprj.importer.ImporterImpl.onPreLoad(ImporterImpl.java:160)
    at com.mycomp.myprj.importer.csv.FileImporter.load(FileImporter.java:43)
    at com.mycomp.myprj.importer.csv.MyImporter.main(MyImporter.java:82)
0.843 seconds

Any idea why this is happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-11-02 18:01:46

只是一个大胆的猜测(我更喜欢 Oracle,而不是 MySQL):
- 您是否可能在 Java 中声明了错误的参数? (my_id在存储过程中被声明为out参数,Java和MySQL中的签名是否匹配?)
- 如果从 MySQL 命令行界面调用过程会发生什么?

亲切的问候,弗兰克

Just a wild guess (I'm more an Oracle than a MySQL kind of guy):
- Did you perhaps declare your parameter in Java wrong? (my_id is declared as an out parameter in the stored procedure, do the signatures in Java and MySQL match?)
- What happens if you call your procedure from the MySQL command line interface?

Kind regards, Frank

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文