VS2013连接MySQL5.6成功案例一枚
如何在VS2013下对MySQL5.6进行连接,本文为大家提供了解决方案,供大家参考,具体内容如下 环境:win832系统,VS2013,MySQL5.6,boost1.60 一种是纯C风格的,不需要使用Connector.C++ 1.1目录下提供的内容。(个人觉得麻烦,代码看着乱,网上有很多资源)。 一种就是利用Connector.C++ 1.1提供的内容,代码简洁,这里只讲这种方法连接数据库。 首先,新建一个VC++的win32空项目。添加源文件,代码如下(代码暂时无法运行,具体配置在后面) #include<cppconndriver.h> #include<cppconnexception.h> #include <cppconn/resultset.h> #include <cppconn/statement.h> #include<mysql_connection.h> #include<iostream> #include<string> using namespace std; int main() { sql::Driver *dirver; sql::Connection *con; sql::Statement *stmt; sql::PreparedStatement *pstmt; sql::ResultSet *res; dirver = get_driver_instance(); //连接数据库 con = dirver->connect("localhost","root","123456"); //选择mydata数据库 con->setSchema("mydata"); con->setClientOption("characterSetResults","utf8"); stmt = con->createStatement(); //从name_table表中获取所有信息 res = stmt->executeQuery("SELECT * from name_table"); //循环遍历 while (res->next()) { //输出,id,name,age,work,others字段的信息 cout << res->getInt("ID") << " | " << res->getString("name") << " | " << res->getInt("age") << " | " << res->getString("work") << " | " << res->getString("others") << endl; } //清理 delete res; delete stmt; delete con; return 0; } 对于以Debug版本运行的程序: 对于以Release版本运行的程序: 为什么区别配置Debug和Release版本? 运行结果: 程序运行结果 以上就是本文的全部内容,希望对大家的学习有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |