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 ...
随机推荐
- 【公司要求】- RPC学习(一)
HADOOP-IPC(这里说的是1.0.4版本) 是轻量级RPC,在hadoop中主要用于2方面 1.TaskTracker和JobTracker 通讯. 2.NameNode和DataNode通讯. ...
- android异步加载图片
import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; impo ...
- Solr的一些查询参数
fl: 是逗号分隔的列表,用来指定文档结果中应返回的 Field 集.默认为 “*”,指所有的字段. defType: 指定query parser,常用defType=lucene, defType ...
- pythonweb自动化测试
from selenium import webdriverimport time def capture(url, save_fn="capture.png"): browser ...
- python 捕获 shell/bash 脚本的输出结果
#!/usr/bin/python## get subprocess module import subprocess ## call date command ##p = subprocess.Po ...
- poj 3744 Scout YYF I (矩阵快速幂 优化 概率dp)
题目链接 分析&&题意来自 : http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710586.html 题意: 在一条不满地雷的 ...
- UVa 1479 (Treap 名次树) Graph and Queries
这题写起来真累.. 名次树就是多了一个附加信息记录以该节点为根的树的总结点的个数,由于BST的性质再根据这个附加信息,我们可以很容易找到这棵树中第k大的值是多少. 所以在这道题中用一棵名次树来维护一个 ...
- HDU 2063 (匈牙利算法) 过山车
有m个妹子和n男生,男生和女生之间互相有好感则连一条线,问最多能撮合出多少对 这篇博文写的很好,没有让人望而生畏的图论术语 http://blog.csdn.net/dark_scope/articl ...
- WEBUS2.0 In Action - 搜索操作指南 - (4)
上一篇:WEBUS2.0 In Action - 搜索操作指南(3) 6. 搜索多个索引 为了提升性能, 我们可以从多个索引同时进行搜索, Webus.Search.MultiSearcher提供了相 ...
- hihoCoder #1179 : 永恒游戏 (暴力枚举)
题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...