mysql-c++连接
1、
mysql-c++连接
MySQL :: Download Connector/C++ https://dev.mysql.com/downloads/connector/cpp/
1-1
VS2015中添加依赖库文件的三种方式 - heibao111728的博客 - CSDN博客
https://blog.csdn.net/heibao111728/article/details/81943953
展开项目——》右击references——》add references——》选择依赖的库文件项目即可。
先从官网下载安装,在查找库文件路径
// mysqlCon.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include "pch.h" #include <iostream> #include <sstream> #include <stdexcept> /* uncomment for applications that use vectors */ /* include <vector> */ #include "jdbc/mysql_connection.h" #include "jdbc/cppconn/driver.h" #include "jdbc/cppconn/exception.h" #include "jdbc/cppconn/resultset.h" #include "jdbc/cppconn/statement.h" #include "jdbc/cppconn/prepared_statement.h" #define EXAMPLE_HOST "l" #define EXAMPLE_USER "l" #define EXAMPLE_PASS "l" #define EXAMPLE_DB "l" using namespace std; /* MySQL :: MySQL Connector/C++ 8.0 Developer Guide :: 3 Installing Connector/C++ from a Binary Distribution https://dev.mysql.com/doc/connector-cpp/8.0/en/connector-cpp-installation-binary.html MySQL :: MySQL Connector/C++ 1.1 Developer Guide :: 7 Connector/C++ Tutorials https://dev.mysql.com/doc/connector-cpp/1.1/en/connector-cpp-tutorials.html MySQL :: MySQL Connector/C++ 1.1 Developer Guide :: 7.1 Prerequisites and Background Information https://dev.mysql.com/doc/connector-cpp/1.1/en/connector-cpp-tutorials-background.html Boost Downloads https://www.boost.org/users/download/ Boost 1.70.0 Library Documentation https://www.boost.org/doc/libs/1_70_0/ */ int main(int argc,const char **argv) { std::cout << "Hello World!\n"; string url(argc >=2 ? argv[1]:EXAMPLE_HOST); const string user(argc >=3 ? argv[2]:EXAMPLE_USER); const string pass(argc >=4 ? argv[3]:EXAMPLE_PASS); const string database(argc >=5 ? argv[4]:EXAMPLE_DB); cout << "Connector /C++ turtorial framework..." << endl; cout << endl; try { /* INSERT TUTORIAL CODE HERE! */ } catch (sql::SQLException &e) { /* MySQL Connector/C++ throws three different exceptions: - sql::MethodNotImplementedException (derived from sql::SQLException) - sql::InvalidArgumentException (derived from sql::SQLException) - sql::SQLException (derived from std::runtime_error) */ cout << "ERR: SQLException in " << __FILE__; cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl; /* what() (derived from std::runtime_error) fetches error message */ cout << "# ERR: " << e.what(); //cout << " (MySql error code: " << e.getErrorCode(); //cout << ", SQLState: " << e.getSQLState() << " )" << endl; return EXIT_FAILURE; } cout << "Done." << endl; return EXIT_SUCCESS; } // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 // 调试程序: F5 或调试 >“开始调试”菜单 // 入门提示: // 1. 使用解决方案资源管理器窗口添加/管理文件 // 2. 使用团队资源管理器窗口连接到源代码管理 // 3. 使用输出窗口查看生成输出和其他消息 // 4. 使用错误列表窗口查看错误 // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件