gpt4 book ai didi

java - 程序如何将mysql中的参数返回给java

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:24 24 4
gpt4 key购买 nike

我正在尝试从 mysql 过程发送一个整数值,该值必须由 Java 类接收。我已经完成了

CREATE DEFINER=`root`@`localhost` PROCEDURE `updateCountry`(o_name varchar(35), u_name varchar(50),m_by varchar(35),out msg int)
BEGIN
if not exists (select country from country where country = u_name) then
UPDATE country SET country= u_name, modify_date=now(), modify_by=m_by where country = o_name;

end if;
if exists (select country from country where country = u_name) then
set msg := '1';
end if;
END

我的 java 类是:

public void modifyCountry(String mod, String real, String crby)throws Exception {
Date d = new Date(System.currentTimeMillis());
System.out.print(d);
CallableStatement cs = conn
.prepareCall("{ call updateCountry(?,?,?,?)}");
cs.setString(1, real);
cs.setString(2, mod);
// cs.setDate(3, d);
cs.setString(3, crby);
cs.registerOutParameter(4, Types.INTEGER);
int check = cs.getInt(4);
System.out.print(check);
cs.execute();
}

这是我得到的错误

No output parameters returned by procedure.

最佳答案

尝试先执行语句再读取输出参数

关于java - 程序如何将mysql中的参数返回给java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17106550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com