iBatis.Net+mysql访问存储过程的问题

本文记录了使用iBatis.Net访问MySQL数据库时遇到的存储过程调用问题,包括错误排查过程及解决方案。作者在尝试执行存储过程的单元测试时,遇到了参数名无法正确附加的问题,通过修改配置文件中provider的parameterPrefix属性,将"?)"替换为"@",最终解决了问题。文章探讨了MySQL中?和@在参数化查询中的差异,并指出可能与驱动程序版本有关。
摘要由CSDN通过智能技术生成

准备选用iBatis.Net做博客的数据持久层,准备写几个demo测测。看它能和mysql数据库友好的玩耍不。


刚开始还挺好的,iBatis.Net能访问mysql数据库。但到了一个存储过程的demo时,好运气终于用光了。我就在网查了查iBatis调用存储过程的例子(IBatisNet系列-执行存储过程IBatis.Net如何获取存储过程的Output的参数值)。

看了这篇文章,我本以为问题已经解决。可以继续愉快的玩耍了。这个是我代码。


1.存储过程及部分sql(mysql)

create table `SysNum`(
  Id int AUTO_INCREMENT not null
  ,Name varchar(100) not null comment '表名'
  ,Num bigint not null default 0 comment '该表对应的编号'
  ,Status int default 0 not null
  ,`Time` TIMESTAMP default now() not null
  ,primary key `P_Id`(`Id`)
  ,unique key `U_Name`(`Name`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='编号表';

create PROCEDURE proc_GetSysNum(in name varchar(100),out n bigint) comment '获取编号'
begin
declare value bigint default (select exists (select Num from SysNum where Name=name));
set @m=0;
if value<>1 then
begin
insert into SysNum(Name,Num,Status)values(name,(select @m:=1),0);
end;
else
begin
update SysNum set Num=@m:=Num+1 where Name=name;
set n=@m;
end;
select n;
end if;
end;

===2014.12.24修正。Name=name永远为true。

DROP PROCEDURE IF EXISTS Duger.proc_GetSysNum;
CREATE PROCEDURE Duger.`proc_GetSysNum`(in m varchar(100),out n bigint)
    COMMENT '获取编号'
begin
set @v:= (select exists (select Num from SysNum where Name=m));
set @m
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值