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

时间:2013-06-14 10:36:25

标签: java mysql

Iam尝试从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.

1 个答案:

答案 0 :(得分:4)

首先尝试执行语句,然后读取输出参数