使用 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. 【js与jquery】jquery循环滚动新闻

    2.html代码: <h3>最新动态</h3> <div class="scrollNews" > <ul> <li>& ...

  2. MVC笔记 Controller相关技术

    一.Controller的责任 MVC的核心就是Controller(控制器),它负责处理浏览器传送过来的所有请求,并决定要将什么内容响应给浏览器.但Controller并不负责决定内容应该如何显示, ...

  3. Linux时间子系统(四) timekeeping

    一.前言 timekeeping模块是一个提供时间服务的基础模块.Linux内核提供各种time line,real time clock,monotonic clock.monotonic raw ...

  4. 计算机硬盘大小转换(B,KB,MB,GB,TB,PB之间的大小转换)

    程序猿都非常懒.你懂的! java程序猿在实际的开发中会遇到非常多的单位换算问题.今天我给大家带来的是关于计算机硬盘大小的换算.多数情况下.一般要求b,kb,mb,gb,tb,pb之间的大小转换,我们 ...

  5. SQL Server 2012 Express LocalDB 的作用

    微软最新推出的 SQL Server 2012 Express LocalDB 是一种 SQL Server Express 的运行模式,特别适合用在开发环境使用,也内置在 Visual Studio ...

  6. CheckedComboBoxEditExtension

    public static class CheckedComboBoxEditExtension { public static void BindData(this CheckedComboBoxE ...

  7. DevExpress下拉多选框 CheckComboboxEdit、CheckedListBoxControl

    CheckComboboxEdit //清空项            checkedComboBoxEdit1.Properties.Items.Clear(); //自定义数组            ...

  8. docker基本概念2

    1 docker 容器,容器可以被创建.启动.停止.删除.暂停等 容器是镜像的一个运行实例,不同的是,他有额外的可写文件层.提供了独立的应用环境. 容器的实质是进程,与宿主机进程不同的是有自己的独立的 ...

  9. 【转】获取scrollTop兼容各浏览器的方法,以及body和documentElement是啥?

    1.各浏览器下 scrollTop的差异 IE6/7/8: 对于没有doctype声明的页面里可以使用  document.body.scrollTop 来获取 scrollTop高度 : 对于有do ...

  10. chkconfig命令具体介绍

    命令介绍: chkconfig命令用来更新.查询.改动不同执行级上的系统服务.比方安装了httpd服务,而且把启动的脚本放在了/etc/rc.d/init.d文件夹下,有时候须要开机自己主动启动它,而 ...