Mysql For Windows c++
来源:互联网 发布:淘宝属于什么行业分类 编辑:程序博客网 时间:2024/05/18 15:29
网上多是关于c 的开发
开发环境 xpsp3 boost_1_48_0 STLport-5.2.1 mysql 5.5.20 server
在windows 下装好 mysql server
在 MySQL 的安装目录下 会有几个文件夹,其中
Connector C++ 1.1.0 //这个c++的
Connector C 6.0.2 //c的
还有java 和 .net 等... 当然也有python 之类的...
如果没有可以下载于:
http://www.mysql.com/downloads/connector/cpp/
到此,还少一个东西 sqlstring.h(我不知道为什么它不提供)
在这里下载
http://download.csdn.net/detail/wangxvfeng101/4056020
请先参考一下网上的mysql 教程(这不在本文之内介绍)
测试条件:
数据库 wxf 中的表 mytable 内容如下:
+-------+------+------------+-----------+
| name | sex | birth | birthaddr |
+-------+------+------------+-----------+
| abccs | f | 1977-07-07 | china |
| aaa | f | 1987-08-27 | beijin |
+-------+------+------------+-----------+
//测试工程:
#include <iostream>#include <stdio.h>#include <mysql_connection.h>#include <mysql_driver.h>#include <cppconn/driver.h>#include <cppconn/exception.h>#include <cppconn/resultset.h>#include <cppconn/statement.h>#include <cppconn/prepared_statement.h>using namespace std;using namespace sql; #pragma comment(lib,"mysqlcppconn.lib") void RunConnectMySQL(){sql::mysql::MySQL_Driver *driver = NULL;sql::Connection *con = NULL;Statement *state = NULL;ResultSet *result = NULL;try{driver = sql::mysql::get_mysql_driver_instance();con = driver->connect("tcp://127.0.0.1:3306","root","000000");//连接数据库state = con->createStatement();state->execute("use wxf");//执行 选中wxf 这个数据库 命令(当然这个我有创建好,怎么创建网上查一下)result = state->executeQuery("select * from mytable");//查询 wxf.mytale 这张表中的所有字段}catch(sql::SQLException & ex)//如果上面有错就捕获这个异常{cout<<ex.what()<<endl;return;} while(result->next()){cout<<"name: "<<result->getString("name").c_str()<<endl;//取出字段为name的所有值}state->close();} void main(){RunConnectMySQL();getchar();;}
几句费话:
不知道为什么 SQLString 对象在VA的提示下会变成指针.... ,这样编译就会出错. 你把->改成. 就好了.
否则会报这类的错误:
__imp_?asStdString@SQLString@sql@@QBEABV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@XZ
mysql c++ 还貌似依赖boost //幸好我有装....
可能是久不写c++代码了 我非要写这样的代码
SQLString strsql = "sss";
string strstd = strql; //这里会报错,我还觉得的奇怪,同一个东西咋就不能哩.
看一下 SQLString 的定义:
class CPPCONN_PUBLIC_FUNC SQLString
{
std::string realStr;
...
}
//它是个类... 并不是个宏,刚开始我一直把它看成是这个宏..... 类似POCO中的XMLString ... 看来是POCO用多了...
http://blog.csdn.net/jgood/article/details/5661339
http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html#trx
- MySql--Install For Windows
- MySql--Install For Windows
- Mysql For Windows c++
- Mysql For Windows安装
- mysql安装for windows
- mysql安装 for windows
- MySQL for Windows安装配置
- Mysql For Windows安装图解
- Mysql For Windows安装图解
- Mysql For Windows安装图解
- Mysql For Windows安装图解
- 第一章:mysql安装for windows
- mysql for windows 密码重置
- DBI DBD-MYSQL 安装(for windows)
- 使用 Mysql 支持中文 for windows
- Database Design Manual: using MySQL for Windows
- cannotcreate windows service for mysql.error:0
- cannot create windows service for MySQL
- IE6下showModalDialog弹出新窗口的问题
- Extjs3.3日期控件的扩展,选择时分秒
- linux下启动oracle
- java的日期计算问题
- poj 1001 Exponentiation 五个小时。。。回来重写
- Mysql For Windows c++
- 深入探究MODVERSIONS的实现原理
- 一些面向对象的设计法则
- Android与服务器端数据交互(基于SOAP协议整合android+webservice)
- SVD分解和LSA的两篇学习资料
- Install Oracle Weblogic Server (WLS) 12c 12.1.1 on Microsoft Windows 7 64 bit
- js 弹出层Demo3
- JSP代码格式化后在IE6中出现的小BUG
- shell中的间接取值