关于MySQL Connector/C++那点事儿
如果从官方直接下载的库使用时遇到类似如下的问题:

原因是官方提供的库文件版本与需要的库版本不匹配,提供的debug版本使用的是MT版本,在debug模式下会出现内存错误,导致crash。
TestC.exe中的...dll有未经处理的异常:读取位置时发生访问冲突。
那么可能需要自己手动编译源码(参考编译MySQL Connector/C++的资料)啦:
重新设置包含目录和库目录(实际中请把想要的头文件和库文件最好放到自己的工程目录里的第三方库或头文件如Libs之类的目录下,保证工程的可一致性,而不是像这里这样F:\Tools\....这样):

重新编译运行:

#include <stdlib.h>
#include <iostream> #include <driver/mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h> using namespace std; int main(void)
{
cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl; try
{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res; /* 连接mysql服务器 */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3307", "root", "*****");
con->setSchema("test"); stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
//通过列别名访问
cout << res->getString("_message") << endl;
//通过列偏移
cout << res->getString(1) << endl;
} delete res;
delete stmt;
delete con;
}
catch (sql::SQLException &e)
{
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cin.get();
return EXIT_SUCCESS;
}
MySQL Connector/C++文档:
http://dev.mysql.com/doc/refman/5.6/en/connector-cpp.html
关于MySQL Connector/C++那点事儿的更多相关文章
- 第11月第20天 sqlite3_open xcode mysql connector
1. sqlite3_open 死锁 * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame ...
- 创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL
创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL 用惯.NET的研发人员都习惯性地使用SQLServer作为数据库.然而.NET Core ...
- vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错
包含头文件 #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/state ...
- Using MySQL Connector .NET 6.6.4 with Entity Framework 5
I had been waiting for the latest MySQL connector for .NET to come out so I can move on to the new a ...
- [转]MySQL Connector/C++(一)
http://www.cnblogs.com/dvwei/archive/2013/04/18/3029464.html#undefined#undefined MySQL Connector/C++ ...
- mysql.connector操作mysql的blob值
This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and re ...
- Ubuntu & MacOS安装Mysql & connector
Ubuntu & MacOS安装Mysql & connector 1. 安装MySql sudo apt-get install mysql-server apt-get insta ...
- Snippet: Fetching results after calling stored procedures using MySQL Connector/Python
https://geert.vanderkelen.org/2014/results-after-procedure-call/ Problem Using MySQL Connector/Pytho ...
- MySQL Connector/J 6.x jdbc.properties 配置, mysql-connector-java-6.0.4.jar 异常
今天学习SSM框架整合,完成Spring和mybatis这两大框架的整合做测试时候出来很多问题,主要来自于配置文件. 我这里重点说一下Mysql数据驱动配置. 配置pom.xml时候去网站 MySQL ...
随机推荐
- Cisco 交换机的操作
Cisco的工作模式 Cisco设备有常用模式为:用户模式.特权模式.全局模式.端口模式.首先它们之间呈现出递进关系:用户模式->特权模式->全局模式->端口模式 1.用户模式 交换 ...
- 怎么在html页面和js里判断是否是IE浏览器
HTML里: HTML代码中,在编写网页代码时,各种浏览器的兼容性是个必须考虑的问题,有些时候无法找到适合所有浏览器的写法,就只能写根据浏览器种类区别的代码,这时就要用到判断代码了.在HTML代码中, ...
- [改善Java代码]不要主动进行垃圾回收
建议51: 不要主动进行垃圾回收 很久很久以前,在Java 1.1的年代里,我们经常会看到System.gc这样的调用—主动对垃圾进行回收.不过,在Java知识深入人心后,这样的代码就逐渐销声匿迹了— ...
- javascript+dom 做javascript图片库
废话不多说 直接贴代码 <!DOCTYPE html><html lang="en"><head> <meta charset=" ...
- Commons IO - IOUtils
IOUtils is a general IO stream manipulation utilities. This class provides static utility methods fo ...
- Java Concurrency - Semaphore 信号量
Semaphore 是一个控制访问多个共享资源的计数器. 当一个线程想要访问某个共享资源,首先,它必须获得 semaphore.如果 semaphore 的内部计数器的值大于 0,那么 semapho ...
- C# 4 dynamic 动态对象 动态类型转换
public class User { //使用省缺参数,一般不需要再为多态做各种静态重载了 public User( string name = "anonym", string ...
- 利用ADO方式连接SQLServer2008出现的问题
在利用ADO方式连接SQLServer2008的过程中遇到了很多问题,在网上也没有找到许多有利的信息,花了两天时间,终于把所有问题都搞定了.在这里和大家分享一下经验,希望后来者能少走弯路. 很多教程说 ...
- Bootstrap引用
<!--设置移动设置页面标准--> <meta name="viewport" content="width=device-width,i ...
- JqGrid 使用方法详解
JQGrid JQGrid是一个在jquery基础上做的一个表格控件,以ajax的方式和服务器端通信. JQGrid Demo 是一个在线的演示项目.在这里,可以知道jqgrid可以做什么事情. 下面 ...