VC++2010配置使用MySQL5.6
0、前提
安装后的文件概览

编译器: VC++2010
MySQL版本:MySQL5.6.19 for win64

Connector版本:connector c++ 1.1.3

在VS2010下配置使用MySQL
1、配置头文件
项目属性--VC++目录--包含目录

2、配置库文件
在connector c++ 1.1.3\lib目录下有两个目录:debug目录 和 opt目录

lib\debug目录

lib\opt目录

由于有debug目录,所以猜测opt目录可能是类似release目录的优化(optimize)后的文件,因此在VC++中使用时在Debug下使用debug目录下的库文件,在Release模式下使用opt目录下的库目录。
eg.
#ifdef _DEBUG
#pragma comment(lib, "debug下的mysqlcppconn.lib")
#pragma comment(lib, "debug下的mysqlcppconn-static.lib")
#else
#pragma comment(lib, "opt下的mysqlcppconn.lib")
#pragma comment(lib, "opt下的mysqlcppconn-static.lib")
#endif
另外,在Debug或Release模式下将debug或opt目录下的mysqlcppcon.dll拷贝到项目目录下或system32目录下。 将 MySQL\MySQL Server5.6\lib目录下的libmysql.dll拷贝到项目目录下或system32目录下。

3、配置项目
由于该版本的MySQL是64位的,因此使用该MySQL的connector的项目必须被配置为X64类型的。 否则会有链接错误! 这一点要注意!

4、Demo
数据库:db_1220, 表:tbl_user, MySQL服务器:本地的localhost

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#pragma warning(disable:4251) #ifdef _DEBUG
#pragma comment(lib, "D:\\Program Files\\MySQL\\Connector C++ 1.1.3\\lib\\debug\\mysqlcppconn-static.lib")
#pragma comment(lib, "D:\\Program Files\\MySQL\\Connector C++ 1.1.3\\lib\\debug\\mysqlcppconn.lib")
#else
#pragma comment(lib, "D:\\Program Files\\MySQL\\Connector C++ 1.1.3\\lib\\opt\\mysqlcppconn-static.lib")
#pragma comment(lib, "D:\\Program Files\\MySQL\\Connector C++ 1.1.3\\lib\\opt\\mysqlcppconn.lib")
#endif using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
sql::Driver *driver = NULL;
sql::Connection *con = NULL;
sql::Statement *stmt = NULL;
sql::ResultSet *res = NULL; sql::SQLString strHost("localhost");
sql::SQLString strUser("root");
sql::SQLString strPwd("XXXXXXX");
sql::SQLString strSchema("db_1220");
sql::SQLString strQuery("select * from tbl_user"); try
{ driver = get_driver_instance(); con = driver->connect(strHost, strUser, strPwd);
con->setSchema(strSchema); stmt = con->createStatement();
res = stmt->executeQuery(strQuery);
sql::ResultSetMetaData* pMetaData = res->getMetaData(); cout << endl; cout << "Results have " << res->rowsCount() << " rows" << endl << endl; while(res->next())
{
//get data by column name
cout << res->getInt("id")
<< " "
<< res->getString("name").c_str() //sql::SQLString没有重载<<操作符,因此不能直接cout<<res->getString("name")
<< " "
<< res->getString("password").c_str()
<< endl; //get data by column index
cout << res->getInt()
<< " "
<< res->getString().c_str()
<< " "
<< res->getString().c_str()
<< endl;
} }
catch (sql::SQLException& e)
{
cerr << endl << e.what() << endl;
}
catch (...)
{
cerr << endl << "some exception happeded" << endl;
} if (NULL != res)
delete res; if (NULL != stmt)
delete stmt; if (NULL != con)
delete con; cout << endl << endl; return ;
}
运行结果:

5、补充
如果在编译过程中报错找不到类似 “<boost/variant.hpp>”这样的错误信息,则是需要boost库支持,下载boost库配置一下即可。
VC++2010配置使用MySQL5.6的更多相关文章
- 配置VC++2010的glut库
VC++2010是一个成熟稳定的版本,微软的编译工具Visual Studio系列从VC6到如今的VC2019,功能非常强大,我们在开始学习C++和计算机图形学的时候,一般入手<<C++P ...
- VC++2010下编译STLport,Boost
VC++2010下编译STLport,Boost 最近在想向Boost转移,努力掌握Boost代码的过程中, STLport版本:5.2.1 Boost版本:1.4.6.1 (1.4.7.0也OK) ...
- VC 2010 Express 学生版(中文版)
Microsoft Visual C++ 2010 Express 学生版 下载传送门(提取码:r7sm) 如何安装 拿到压缩文件后,解压到桌面(别怕,安装完后这个文件夹是可以删除的). 在 &quo ...
- TFS 2010 配置的时候,提示TF255466错误
TFS 2010 配置的时候,提示TF255466错误 Error [ System Checks ] TF255466: The configuration process for Team Fou ...
- VC项目配置基础以及快捷键(收藏)
来自http://blog.csdn.net/phunxm/article/details/5082488 一.IDE基础配置 1.字体 VC6中“Tools→Options→Format→Font” ...
- visual studio 2010配置驱动开发环境
visual studio 2010 配置驱动开发环境 ** 工具/材料 VS2010.WDK开发包 ** 配置过程 以下将讲述VS2010驱动开发环境的配置过程,至于必要软件的安装过程这里不再赘述 ...
- VC#2010 视图设计器无法打开 问题的正解
继上次VC#2010中视图设计器无法打开的问题的讨论后,我感觉每次都重新安装一次安装包未免也太麻烦了,程序员的时间都灰常宝贵. 所以在这次人工智能作业的时候,找到了一个简单的途径: 打开VC#2010 ...
- MySQL安装 MySQL5.7.10免安装版配置,mysql5.7.10免安装版
MySQL5.7.10免安装版配置,mysql5.7.10免安装版 最新版的 Mysql 不提供图形界面的安装了, 下载下来是一个压缩包的形式, 那么我们如何来使用它呢, 让它为我们工作呢? 环境: ...
- Systemc在VC++2010安装方法及如何在VC++2010运行Noxim模拟器
Systemc在VC++2010的安装方法可以参考文档"Systemc with Microsoft Visual Studio 2008.pdf".本文档可以在"htt ...
随机推荐
- 【转】RESTful Web Services初探
近几年,RESTful Web Services渐渐开始流行,大量用于解决异构系统间的通信问题.很多网站和应用提供的API,都是基于RESTful风格的Web Services,比较著名的包括Twit ...
- Java:抽象类abstract和接口Interface
一.抽象类:abstract 抽象类就是为了继承而存在的,如果你定义了一个抽象类,却不去继承它,那么等于白白创建了这个抽象类,因为你不能用它来做任何事情.对于一个父类,如果它的某个方法在父类中实现出来 ...
- Bootstrap学习笔记之整体架构
之前有粗略地看过一下Bootstrap的内容,不过那只是走马观花式地看下是怎么用的,以及里面有什么控件,所以就没想着记笔记.现在由于要给部门做分享,所以不得不深入地去学习下,不然仅是简单地说下怎么用, ...
- SSIS ->> 通过Checkoints实现SSIS的包重启(Package Restartability Fullfilled By Checkoints)
Checkpoints是实现SSIS包重载的基础.它的原理是把当前运行环境的配置.变量以及到了包运行到哪一步和哪一步失败这些信息写入到一个文件中.而且有一点很重要,Checkpoint只发生在Cont ...
- linux网络相关
ethtool:http://www.ibm.com/developerworks/cn/linux/1304_wangjy_ethtools/ 网卡特性:http://blog.chinaunix. ...
- sizeof()与strlen()的区别
首先需要说明的是sizeof和strlen都可以求长度,但是却有很大的区别,简单来说可以概括为以下几点: 1.sizeof是一个关键字,而strlen确实一个函数. 2.sizeof求的是字节长度,而 ...
- allegro使用汇总 [转贴]
1.如何在allegro中取消花焊盘(十字焊盘) set up->design parameter ->shape->edit global dynamic shape parame ...
- MTK6577+Android环境变量
1. 环境变量机器对应的路径 $project = hsimobile77_ics2 $platform=mt6577 $(PRODUCT_OUT)=\out\target\product\$proj ...
- supersocket中quickstart文件夹下的MultipleCommandAssembly的配置文件分析
首先确认下配置文件中的内容 第一部分configSections[需要注意的是name=superSocket] <configSections> <section name=&qu ...
- leetcode:Isomorphic Strings
Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are isom ...