Can';java中的t exec SQL存储过程

Can';java中的t exec SQL存储过程,java,sql,stored-procedures,Java,Sql,Stored Procedures,我有一个SQL中的存储过程,可以在SQL中运行而不会出现问题。但当我使用Java调用它时,代码可以运行,但不能调用存储过程。这是我的密码: public int countPV(int value){ Connection conn = null; ResultSet rs = null; try { conn = MyConection.getConnection(); CallableStatement cstmt = conn.pr

我有一个SQL中的存储过程,可以在SQL中运行而不会出现问题。但当我使用Java调用它时,代码可以运行,但不能调用存储过程。这是我的密码:

public int countPV(int value){
    Connection conn = null;
    ResultSet rs = null;

    try {
        conn = MyConection.getConnection();
        CallableStatement cstmt = conn.prepareCall("{call countPV(?)}");
        cstmt.setInt(1, value);
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }finally{
        try {

            MyConection.closeConnection(conn, null, rs);
        } catch (Exception e) {
        }
    }
    return 1;

}
下面是我的SQL存储过程:

CREATE procedure countPV (@pID int)
as
begin
WHILE (2>1)
BEGIN
    update tblUser
    set countx = countx + 1
    where ID = @pID
    SET @pID = (select parentID from tblUser where ID = @pID)
    if(@pID = (select parentID from tblUser where ID = @pID))
    break;
END
end

您需要在方法中调用
CallableStatement#execute()

CallableStatement cstmt = conn.prepareCall("{call countPV(?)}");
cstmt.setInt(1, value);

cstmt.execute(); // MISSING!

由于CallableStatement是对PreparedStatement的扩展,它继承了它的执行方法(execute、executeQuery、executeUpdate),以便像普通quires一样执行


我建议对任何存储过程调用使用
setQueryTimeout
,以避免超时问题。

那么错误是什么呢?JAVA中没有错误。但是store不能在sqlexec中执行可能您只是缺少了一个
commit