本文介绍了从java中的mysql存储过程中获取参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在从Java中的mysql存储过程中检索OUT参数时遇到问题.
I am having problem retrieving OUT parameter from mysql stored procedure in java.
CALL proc_after_topic_add('newtest',@result);
SELECT @result;
此查询为我提供了所需的out参数,但是我将如何在java中检索它?我尝试使用CallableStatement但得到
this query gives me desired out parameter but how would i retrieve it in java.I tried using CallableStatement but i get
java.sql.SQLException: Callable statments not supported.
错误.请大家帮帮我.我已经尝试关注
error.Please guys help me.I have tried following
String sql = "CALL proc_after_topic_add(?,?);";
CallableStatement cstmt = conn.prepareCall(sql);
cstmt.setString(1, topicname);
cstmt.registerOutParameter(2, java.sql.Types.INTEGER);
ResultSet rs = cstmt.executeQuery();
if (rs.next()) {
if (rs.getInt(1) == 1) {
res = 0;
} else {
res = -1;
}
}
我没有发布存储过程代码,因为它没有错.
I havent posted stored procedure code because there is nothing wrong with it.
PS:I a using mysql 5.5.21 and yes i should probably mention i am using mysql connector 3.0.15
好的,这已经解决.对于遇到相同问题的任何人,只需下载最新版本的mysql连接器即可.
推荐答案
此行中的错误
cstmt.registerOutParameter(2, java.sql.Types.INTEGER);
像这样更改
String sql = "CALL proc_after_topic_add(?,?);";
cstmt.registerOutParameter(2, java.sql.Types.INTEGER);
这篇关于从java中的mysql存储过程中获取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!