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的更多相关文章

  1. 配置VC++2010的glut库

    VC++2010是一个成熟稳定的版本,微软的编译工具Visual Studio系列从VC6到如今的VC2019,功能非常强大,我们在开始学习C++和计算机图形学的时候,一般入手<<C++P ...

  2. VC++2010下编译STLport,Boost

    VC++2010下编译STLport,Boost 最近在想向Boost转移,努力掌握Boost代码的过程中, STLport版本:5.2.1 Boost版本:1.4.6.1 (1.4.7.0也OK) ...

  3. VC 2010 Express 学生版(中文版)

    Microsoft Visual C++ 2010 Express 学生版 下载传送门(提取码:r7sm) 如何安装 拿到压缩文件后,解压到桌面(别怕,安装完后这个文件夹是可以删除的). 在 &quo ...

  4. TFS 2010 配置的时候,提示TF255466错误

    TFS 2010 配置的时候,提示TF255466错误 Error [ System Checks ] TF255466: The configuration process for Team Fou ...

  5. VC项目配置基础以及快捷键(收藏)

    来自http://blog.csdn.net/phunxm/article/details/5082488 一.IDE基础配置 1.字体 VC6中“Tools→Options→Format→Font” ...

  6. visual studio 2010配置驱动开发环境

    visual studio 2010 配置驱动开发环境 ** 工具/材料 VS2010.WDK开发包 **  配置过程 以下将讲述VS2010驱动开发环境的配置过程,至于必要软件的安装过程这里不再赘述 ...

  7. VC#2010 视图设计器无法打开 问题的正解

    继上次VC#2010中视图设计器无法打开的问题的讨论后,我感觉每次都重新安装一次安装包未免也太麻烦了,程序员的时间都灰常宝贵. 所以在这次人工智能作业的时候,找到了一个简单的途径: 打开VC#2010 ...

  8. MySQL安装 MySQL5.7.10免安装版配置,mysql5.7.10免安装版

    MySQL5.7.10免安装版配置,mysql5.7.10免安装版  最新版的 Mysql 不提供图形界面的安装了, 下载下来是一个压缩包的形式, 那么我们如何来使用它呢, 让它为我们工作呢? 环境: ...

  9. Systemc在VC++2010安装方法及如何在VC++2010运行Noxim模拟器

    Systemc在VC++2010的安装方法可以参考文档"Systemc with Microsoft Visual Studio 2008.pdf".本文档可以在"htt ...

随机推荐

  1. Redis的Set操作

    集合的性质: 唯一性,无序性,确定性 注: 在string和link的命令中,可以通过range 来访问string中的某几个字符或某几个元素 但,因为集合的无序性,无法通过下标或范围来访问部分元素. ...

  2. Linux命令-date

    [root@localhost ~]# date 2016年 09月 07日 星期三 :: CST [root@localhost ~]# date "+%Y" [root@loc ...

  3. 笔者带你剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER)

    注:本文部分内容引用本人博客http://gao-xianglong.iteye.com/blog/1973591   前言 在开始讲解淘宝的TDDL(Taobao Distribute Data L ...

  4. Vim 新用法

    daw , delete a word cw , delete from cursor to the end then insert mode a word 移动: f ; Aa Oo Cc Ii S ...

  5. 《c程序设计语言》读书笔记--每行一个单词打印输入的字符,除去空符

    #include <stdio.h> int main() { int c; while((c = getchar()) != EOF) { if(c != '\n' && ...

  6. H5移动前端完美布局之padding

    序上次的提到了H5移动前端完美布局之-margin百分比的使用margin-top(left,right,bottom)的百分比在移动页面布局中对上下左右距离的处理,攻下城外再攘城内,今天看看padd ...

  7. [POJ1631]Bridging signals (DP,二分优化)

    题目链接:http://poj.org/problem?id=1631 就是求一个LIS,但是范围太大(n≤40000),无法用常规O(n²)的朴素DP算法,这时需要优化. 新加一个数组s[]来维护长 ...

  8. 没有显示器且IP未知的情况下登录树莓派

    如果是没有显示器操作树莓派,可能会不知道树莓派有线网卡自动分配到的IP地址,不知道登录到哪儿.以下提供详细操作步骤解决这个问题. 网段扫描法这个是推荐的办法.网段扫描工具很多,推荐一个Advanced ...

  9. php面试题整理

    PHP经典面试题:(不断跟进补充中...) 1.用PHP打印出前一天的时间格式是2009-02-10 22:21:21(2分) echo date('Y-m-d H:i:s', strtotime(' ...

  10. objective-c 与 js之间传递中文乱码

    最近在做关于js改写oc framework的小project,遇到了不少问题 其中刚遇到的是关于如何在两者之间传递中文字符,带特殊字符的URL字符串 不会很详细的介绍太多,以后会回头做个总结 oc传 ...