执行带有事务管理的存储过程,是否能返回实际执行的条数?

[复制链接]
查看11 | 回复2 | 2010-5-10 11:24:21 | 显示全部楼层 |阅读模式
用Java调用mysql存储过程,本想执行返回值为影响的条数,可执行成功返回值却为0。
存储过程如下:
BEGIN
start transaction;
insert tb_answers(a_question_id,a_user_id,a_context,a_picture,a_answer_time,a_best) values (question_id,user_id,context,picture,answer_time,best);
update tb_questions set q_answers_amount=q_answers_amount+1 where q_id=question_id;
if @@error_count = 0 then
commit;

else

rollback;

end if;
END
请问,这样返回0是正确的吗?(注:如果我不加事务管理,就能够返回实际执行的条数。)
to 星雨星郁: 似乎mysql存储过程里不能写return语句。
to gaind: 用select语句是可以获取数据,可是我代码里还要解析,觉得太麻烦,我希望直接获得存储过程被executeUpdate执行后返回的int值。
另外,请问一下我那样写法返回0是正确的吗?

回复

使用道具 举报

千问 | 2010-5-10 11:24:21 | 显示全部楼层
BEGIN start transaction; decalre @insert_count int, decalre @update_count int, set @insert_count = (insert tb_answers(a_question_id,a_user_id,a_context,a_picture,a_answer_time,a_best) values (question_id,user_id,context,picture,answer_time,best)); set @update_count = (update tb_questions set q_answers_amount=q_answers_
回复

使用道具 举报

千问 | 2010-5-10 11:24:21 | 显示全部楼层
可以 在该跳出的地方 RETURN @@ROWCOUNT;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行