MySql: ”Commands out of sync“Error (Connect/C++)

使用 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(1,1001);
        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(1,1001);
        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());
时间: 2024-10-12 19:00:26

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

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

1.代码如下: void TestCache(otl_connect& otlConn) { try { char sql[1024] = {0}; sprintf(sql,"call test1(1)"); otl_stream stream(100, sql, otlConn,otl_implicit_select); int id; while(!stream.eof()) { stream>>id; char sql2[1024] = {0}; sprint

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

原来一直是使用MySQL安装版没有出现过问题,今天在安装绿色版MySQL时出现了点问题 在安装成windows服务成功后,用net start mysql 启动时提示启动成功,但当我连接mysql就报以下错误: ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061) my.ini文件内容: [mysqld]basedir=E://databases//mysqldatadir=F://databases//

在启动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)", 情况如图: 2.问题分析 从错误的提示中可以看出MySQL服务没有启动,因此只需要启动MySQL服务就可以了. 3.问题解决 直接采用net start MySQL 就可以启动MySQL服务,但是输入命令后仍然出现错误: 可以看到错误提示:"服务名无效",说明不存在MySQL

ORA-00257: archiver error.Connect internalonly, until freed 后续之 delete force

前言--现象描述 远程plsq登录报错" ORA-00257: archiver error.Connect internalonly, until freed alert后台日志报错: Errors in file/oracle/app/oracle/diag/rdbms/pdunq/ptext/trace/ptext_arcc_19603.trc: ORA-19809: limit exceeded for recoveryfiles ORA-19804: cannot reclaim 42

mysql更改数据库目录提示“ERROR 2002 (HY000): '/var/lib/mysql/mysql.sock' (2)”

操作系统环境如下: [[email protected] data]# cat /etc/issue CentOS release 6.7 (Final) Kernel \r on an \m [[email protected] data]# uname -r 3.19.0-25-generic [[email protected] data]# getconf LONG_BIT 64 mysql数据库由于yum安装方式,所以默认的数据库目录是/var/lib/mysql,也就是my.cnf文

yum安装mysql步骤及报错ERROR 1045 (28000)

1.centos 系统中使用yum工具安装 mysql. [[email protected] ~]#yum install -y mysql 2.yum install -y mysql后,启动mysql报错如下: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 解决办法:缺少组件,安装mysql-server包. 3.安装组件mysql

ORA-00257: archiver error. Connect internal only, until freed

ORA-00257: archiver error. Connect internal only, until freed 原因是日志满了,根据上述网址提供的步骤操作后就可以,即删除部分归档日志. 1.首先查看当前flash recovery area使用情况 C:\windows\system32>sqlplus sys/[email protected] as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期三 9月 4 18:08:4

命令行连接mysql服务器时 报Can't connect to local MySQL server through socket 'xxx.sock'错误

本来之前用的好好的mysql服务器,突然就报Can't connect to local MySQL server through socket 'xxx.sock'错误了 遇到该问题思路首先是:检查 my.cnf 中 socket 配置的路径及权限. 但是查看完 没发现路劲权限有问题,最后跑去另一台同时配置的服务器上看  发现/data/perconadata有一个/mnt/perconadata/mysql.sock的软连接 于是乎到问题机器上 cd /data/perconadata/ s

mysql主从连接报错ERROR 1201

做主从同步时的报错: mysql> change master to master_host='192.168.10.151',master_user='repl',master_password='zrer90',master_log_file='mysql2-bin.000004',master_log_pos=98; ERROR 1201 (HY000): Could not initialize master info structure; more error messages can