关于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 ...
随机推荐
- win8.1恢复win7 CTRL+Space切换输入法
win8用起来还是有很多好用的东西的,但是最让我受不了的就是输入法的切换,可以说是丧心病狂!!!折磨了我好久,今天终于找到了解决的办法! 那就是这位博客园的哥们给出的方案! http://www.cn ...
- Volley 源码解析
Volley 源码解析 1. 功能介绍 1.1. Volley Volley 是 Google 推出的 Android 异步网络请求框架和图片加载框架.在 Google I/O 2013 大会上发布. ...
- discuze回放提示“抱歉,您的请求来路不正确或表单验证串不符,无法提交”
不知从哪里看到文章,但是实用: 背景:discuze就单纯的录制一个注册脚本,日志中没有报错,在报告中就提示"抱歉,您的请求来路不正确或表单验证串不符,无法提交"",以下 ...
- java按行读取txt并按行写入
IO流想必大家都很熟悉了,本次实现的需求是按行读取文件内容并且按行写入,代码如下: try { String encoding="utf-8"; //设定自己需要的字符编码集 Fi ...
- HDOJ2029Palindromes _easy version
Palindromes _easy version Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- JSP之Cookie
Cookie是小段的文本信息,在网络服务器上生成,并发送给浏览器,通过使用cookie可以标识用户身份,记录用户名和密码,跟踪重复等. 首先创建index.jsp: <%@page import ...
- php中preg_match用户名正则实例
例子,字母.数字和汉字 代码如下 复制代码 if(preg_match("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|]|[|/|\|"||/& ...
- Block深入浅出
研究工具 clang 为了研究编译器的实现原理,我们需要使用 clang 命令.clang 命令可以将 Objetive-C 的源码改写成 C / C++ 语言的,借此可以研究 block 中各个特性 ...
- windows搭建virtualbox虚拟机安装的android环境
1.首先安装virtualbox,从官网下载,安装完成之后在本地连接里面有virtualbox虚拟的网卡,可能会影响网络连接,一般禁用 2.下载android的镜像,完整名称是:android-x86 ...
- 快速搭建MongoDB分布式集群
目录Outline 1. prerequisites 2. steps to follow3. configuring the cluster4. a little test to see 1. Pr ...