【发布时间】:2023-03-30 03:32:01
【问题描述】:
我有一个 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
【问题讨论】:
-
那么错误是什么?
-
JAVA 没有错误。但是存储不能在 SQL 中执行
-
也许你只是错过了
commit?
标签: java sql stored-procedures