我在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
}这个存储过程在我的本地计算机(WindowsServer5.1、MySQL 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你知道为什么会发生这种事吗?
发布于 2011-03-28 21:53:55
这只是一个大胆的猜测(我更像是一个甲骨文而不是MySQL类型的人):
你是不是在中声明了错误的参数?(my_id在存储过程中声明为out参数,Java和MySQL中的签名是否匹配?)
致以良好的问候,弗兰克
https://stackoverflow.com/questions/5459919
复制相似问题