当我从java代码插入记录时mysql触发器不起作用
DELIMITER //
DROP TRIGGER insert_orderinward_trig; //
CREATE TRIGGER insert_orderinward_trig AFTER INSERT ON tblm_tlmngorderinward FOR EACH ROW
BEGIN
call temp_proc(NEW.itemcode);
END; //
我编写程序,因为
DELIMITER //
DROP PROCEDURE temp_proc; //
CREATE PROCEDURE temp_proc(IN code VARCHAR(80))
BEGIN
DECLARE inwardstock,issuestock,updatestock DECIMAL(15,0) DEFAULT 0;
SET inwardstock = (SELECT SUM(stock) FROM tblm_tlmngorderinward WHERE itemcode = code);
IF(@inwardstock > 0) THEN
SET updatestock =inwardstock;
END IF;
SET issuestock = (SELECT SUM(stock) FROM tblt_tlmngissueitem WHERE itemcode = code);
IF(@issuestock > 0) THEN
SET updatestock = @updatestock-@issuestock ;
END IF;
UPDATE tblm_tlmngitem SET stock=updatestock WHERE itemcode=code;
END; //
DELIMITER ;
当我手动插入记录时,我的插入触发器工作正常。但是当我在java中使用preparestatement插入记录时它无法工作。
DELIMITER //
DROP TRIGGER insert_orderinward_trig; //
CREATE TRIGGER insert_orderinward_trig AFTER INSERT ON tblm_tlmngorderinward FOR EACH ROW
BEGIN
call temp_proc(NEW.itemcode);
END; //
I write procedure as
DELIMITER //
DROP PROCEDURE temp_proc; //
CREATE PROCEDURE temp_proc(IN code VARCHAR(80))
BEGIN
DECLARE inwardstock,issuestock,updatestock DECIMAL(15,0) DEFAULT 0;
SET inwardstock = (SELECT SUM(stock) FROM tblm_tlmngorderinward WHERE itemcode = code);
IF(@inwardstock > 0) THEN
SET updatestock =inwardstock;
END IF;
SET issuestock = (SELECT SUM(stock) FROM tblt_tlmngissueitem WHERE itemcode = code);
IF(@issuestock > 0) THEN
SET updatestock = @updatestock-@issuestock ;
END IF;
UPDATE tblm_tlmngitem SET stock=updatestock WHERE itemcode=code;
END; //
DELIMITER ;
My insert trigger work fine when i manually insert record. But it can not work when i insert record using preparestatement in java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
乍一看,您似乎有两个变量 inwardstock/@inwardstock 和 issuesstock/@issuestock ,这看起来是错误的:
我的另一个建议是完全放弃触发器并只调用存储过程:
希望这会有所帮助:)
On first glance you seem to have 2 variables for inwardstock/@inwardstock and issuestock/@issuestock which looks wrong:
The other suggestion I have is to drop the trigger completely and just call a stored proc:
Hope this helps :)