去官网下载,分为release模式和debug模式两种,分别对应VS中的release和debug。如下图所示: 注意: 如果使用debug模式,下载的上面的release模式库文件,那么编译就会出
#include
try {//初始化接口并连接sql::mysql::MySQL_Driver* driver;sql::Connection* con;sql::Statement* stat;driver = sql::mysql::get_driver_instance();con = driver->connect("tcp://127.0.0.1:3306", "root", "root");con->setSchema("schema");//数据库名称//查询stat = con->createStatement();/// 准备 SQL 查询语句,并执行sql::Statement* stmt = con->createStatement();//PreparedStatement* pstmt = conn->prepareStatement("SELECT * FROM temperature ORDER BY time DESC LIMIT 1");sql::ResultSet* res = stmt->executeQuery("SELECT * FROM temperature ORDER BY time DESC LIMIT 1");// 遍历结果集,并输出查询结果while (res->next()) { double temperature = res->getDouble("temperature"); string time = res->getString("time"); cout << "temperature: " << temperature << ", time: " << time << endl;}// 释放资源delete res;delete stmt;delete con;}//异常抛出catch (sql::SQLException& e) {cout << "Error: " << e.what() << endl;}
相关链接:
来源地址:https://blog.csdn.net/weixin_44242113/article/details/129158640
--结束END--
本文标题: C++使用MySQL Connector/C++访问mysql数据库
本文链接: https://www.lsjlt.com/news/395654.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0