在名为chapter06的数据库中成功创建了一个存储过程,代码如下:
create procedure addcount (out count int)
begin
declare itmp int;
declare cur_id cursor for select id from stu;
declare exit handler for not found close cur_id;
select count(*) into count from stu;
set @sum =0;
open cur_id;
repeat
fetch cur_id into itmp;
if itmp <10
then set @sum = @sum +itmp;
end if;
until 0 end repeat;
close cur_id;
end //
然后编写了一个Java程序,连接到chapter06,执行存储过程,代码如下:
import java.sql.*;
public class TestProc {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection cnn = DriverManager.getConnection("jdbc:mysql://localhost/chapter06?user=root&password");
CallableStatement cs = cnn.prepareCall("{call addcount(?)");
cs.registerOutParameter(1, Types.INTEGER);
cs.execute();
System.out.println(cs.getInt(1));
} catch (Exception e) {
e.printStackTrace();
}
}
}
执行该程序,命令行窗口提示java.sql.SQLException: Parameter number 1 is not an OUT parameter,请问怎么回事?