vs2008 C++项目连接mysql数据库详解
来源:互联网 发布:java框架怎么用 编辑:程序博客网 时间:2024/06/05 03:55
一、运行环境:
Win7 32bit
Vsiual C++ 2010、
MySQL5.6、
MySQL Connector C++ 1.1.6、 //安装Windows 32位版本的MySQL5.6的连接器
boost_1_58_0 //在“MySQL Connector C++ 1.1.6”中用到。
二、参考文章:
VS2008下C++连接Mysql http://blog.sina.com.cn/s/blog_7929e19f0101l0oi.html
http://dev.mysql.com/doc/connector-cpp/en/index.html //MySQL Connector C++ 的参考文档、
//mysql-connector-cpp-en.a4.pdf 下载的PDF官方文档
三、编译完成后加入官方文档中的例子代码:
#include "stdafx.h"#include<stdlib.h>#include<iostream>//下面是mysql的依赖头文件#include "mysql_connection.h"#include <cppconn\driver.h>#include <cppconn\exception.h>#include <cppconn\sqlstring.h>#include<cppconn\resultset.h>#include <cppconn\statement.h>using namespace std;int _tmain(int argc, _TCHAR* argv[]){cout << endl;cout << "Running 'SELECT' Hello World!' \AS _message'..." << endl;try {sql::Driver *driver;sql::Connection *con;sql::Statement *stmt;sql::ResultSet *res;/* Create a connection */driver = get_driver_instance();con = driver->connect("tcp://127.0.0.1:3306", "root", "root");/* Connect to the MySQL test database */con->setSchema("test");stmt = con->createStatement();res = stmt->executeQuery("SELECT 'Hello World!' AS _message");while (res->next()) {cout << "\t... MySQL replies: ";/* Access column data by alias or column name */cout << res->getString("_message") << endl;cout << "\t... MySQL says it again: ";/* Access column fata by numeric offset, 1 is the first column */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;}cout << endl;return 0;}
0 0
- vs2008 C++项目连接mysql数据库详解
- vs2008 C++项目连接mysql数据库详解
- vs2008 C++项目连接mysql数据库详解
- MySQL:vs2008下c#连接MySQL数据库
- vs2008 连接mysql (用C语言连接)
- vs2008 连接mysql (用C语言连接)
- VS2008项目使用C++连接MySQL
- vs2008下c#连接MySQL数据库
- vs2008连接MySQL,采用C API方式
- vs2008连接MySQL,采用C API方式
- c连接mysql数据库
- c连接mysql数据库
- c 连接mysql数据库
- cygwin下用mysql c api连接数据库详解
- java 项目连接mysql 数据库
- 【数据库】Mysql的连接详解
- servlet连接mysql数据库详解
- Weka连接MySQL数据库详解
- Java基础---IO流
- 初窥ElasticSearch
- Less mobile, more everything-重新思考Mobile
- 兔子--html,js,php,ASP,ASP.NET,JSP的关系
- 1: 错误: 非法字符: \65279
- vs2008 C++项目连接mysql数据库详解
- “Core Data could not fulfill a fault” for objects that were not deleted
- android sdk更新hosts修改
- LeetCode || Rotate Array
- adb shell 命令详解
- [学习笔记—算法] 打印1~10整数的阶乘表
- 各大搜索引擎自动提示API
- 1.安装MySQL
- Zend_Form Decorators使用实例