使用 Connector/C++ 查询 Mysql , 连续调用存储过程时

会出现如下:

Commands out of sync; you can't run this command now,state:HY000

出现原因可以看这里:http://stackoverflow.com/questions/17115919/mysql-commands-out-of-sync-error-c-connector

这一句:

Because CALL can return multiple results, process them using a loop that calls mysql_next_result() to determine whether there are more results. "

Connector/C++ 封装后,使用  getMoreResults() 函数来读取下一个 resultset;

例子如下:

     // 查询存储过程
prepareState.reset(con->prepareStatement("call test.testproc1(?)"));
prepareState->setInt(,);
prepareState->executeUpdate(); result.reset(prepareState->getResultSet());
// 输出结果
while(result->next())
{
int id = result->getInt("id");
string name = result->getString("name");
} while(prepareState->getMoreResults()) //注意这里, 调用 getMoreResults() 把所有的 resultset读出来
{
result.reset(prepareState->getResultSet()); //对下一组result set 做某些东西
}
      
prepareState.reset(con->prepareStatement("call test.testproc3(?)"));
prepareState->setInt(,);
prepareState->executeUpdate(); result.reset(prepareState->getResultSet());
// 输出结果
while(result->next())
{
int id = result->getInt("id");
string name = result->getString("name");
} while (prepareState->getMoreResults())
result.reset(prepareState->getResultSet());

MySql: ”Commands out of sync“Error (Connect/C++)的更多相关文章

  1. 使用otl,报错:mysql Commands out of sync; you can't run this command now

    1.代码如下: void TestCache(otl_connect& otlConn) { try { ] = {}; sprintf(sql,"call test1(1)&quo ...

  2. python mysql 2014 Commands out of sync; you can't run this command now

    这个问题出现再 mysql和c  的api. 简单的解决方法是不使用api直接把整个连接和命令传过去. 例如,cmd = 'mysql -h 192.168.32.210 -P 3316 -u bfd ...

  3. error:2014 Commands out of sync; you can't run this command now

    如下错误: 分析原因: 前端ajax请求后台,共用同一个链接. 搜索别人的解决方案:http://blog.csdn.net/grass_ring/article/details/3499402 用m ...

  4. mysql绿色版安装问题解决(ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061))

    原来一直是使用MySQL安装版没有出现过问题,今天在安装绿色版MySQL时出现了点问题 在安装成windows服务成功后,用net start mysql 启动时提示启动成功,但当我连接mysql就报 ...

  5. 在启动MYSQL时出现问题:“ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)”

    1.问题描述 在启动MYSQL时出现问题:"ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)& ...

  6. 一则奇怪的案例处理:ORA-00257: archiver error. Connect internal only, until freed

    前天,业务反应数据库不能连接 在操作系统通过字符串尝试登陆数据库报:ORA-00257: archiver error. Connect internal only, until freed 解决思路 ...

  7. 【Oracle】ORA-00257:archiver error. Connect internal only, until freed 错误的处理方法

    archive log 日志已满ORA-00257: archiver error. Connect internal only, until freed 错误的处理方法 1. 用sys用户登录  s ...

  8. mysql闪退或者can not connect 127.0.0.1

    MYSQL 无安装文件 exe执行时闪退 mysql闪退或者can not connect 127.0.0.1 APP 百款主流机型兼容性免费测 »   Mysql  官网上下载的Mysql 但是没有 ...

  9. ORA-00257: archiver error. Connect internal only, until freed——解决

    参考http://www.2cto.com/database/201109/104615.html, 开启归档后,操作一个大表迁移表空间,执行了1个多小时没完成就手动给中断了,但是再次用plsql登陆 ...

随机推荐

  1. 通俗易懂,C#如何安全、高效地玩转任何种类的内存之Span的脾气秉性(二)。 异步委托 微信小程序支付证书及SSL证书使用 SqlServer无备份下误删数据恢复 把list集合的内容写入到Xml中,通过XmlDocument方式写入Xml文件中 通过XDocument方式把List写入Xml文件

    通俗易懂,C#如何安全.高效地玩转任何种类的内存之Span的脾气秉性(二).   前言 读完上篇<通俗易懂,C#如何安全.高效地玩转任何种类的内存之Span的本质(一).>,相信大家对sp ...

  2. Factory - 工厂模式

    在面向对象编程中, 最通常的方法是一个new操作符产生一个对象实例,new操作符就是用来构造对象实例的.但是在一些情况下, new操作符直接生成对象会带来一些问题.举例来说, 许多类型对象的创造需要一 ...

  3. 尾递归与Continuation

    怎样在不消除递归的情况下防止栈溢出?(无论如何都要使用递归) 这几天恰好和朋友谈起了递归,忽然发现不少朋友对于“尾递归”的概念比较模糊,网上搜索一番也没有发现讲解地完整详细的资料,于是写了这么一篇文章 ...

  4. Python rsplit() 方法

    描述 Python rsplit() 方法通过指定分隔符对字符串进行分割并返回一个列表,默认分隔符为所有空字符,包括空格.换行(\n).制表符(\t)等.类似于 split() 方法,只不过是从字符串 ...

  5. 三极管工作区在Spectre中的表示

    三极管的工作区在Spectre中通过静态工作点的region字段表示,具体表示如下: region: 0:off 1:fwd 2:rev 3:sat 4:breakdown 可在终端中输入 : ”sp ...

  6. Latex 附录生成方法-附使用的一些tips

    Latex 附录生成方法-附使用的一些tips 工具 使用latex写论文时,国内科研人员使用比较多的前端工具当属CTex,另外的前度工具有texstdio,texworks,sublime,甚至vi ...

  7. vim-snipmate编写snippet的语法

    vim-snipmate真的很好用,以前好多编写代码的问题得到完美的解决.还附带提升我对vim的理解和信心,在这里感谢一下作者.thank you. 1.现说一下我浓缩的重要语法. 1.定义是下面这样 ...

  8. 一些常见的关于Linux系统的问题

    1 如何看当前Linux系统有几颗物理CPU和每颗CPU的核数? 答:[root@centos6 ~ 10:55 #35]# cat /proc/cpuinfo|grep -c 'physical i ...

  9. Linux minilogd占用内存过高及开机启动项修改

    minilogd: 今天发现一台服务起的内存正常占用应该在70左右,但是内存占用却到了90%以上,用top查看发现minilogd占用了30%左右的内存,是不符合预期的,查看开机启动项并无minilo ...

  10. hdoj 1027 Ignatius and the Princess II 【逆康托展开】

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...