提问人:Alankrita Asthana 提问时间:11/18/2023 更新时间:11/18/2023 访问量:19
VS Code MySQL/C++ 连接器配置设置 [已关闭]
vs code mysql/c++ connector configuration settings [closed]
问:
我正在尝试在 VS 代码中使用 mysql/c++ 连接器库连接到 mysql 数据库。我已经安装了 c++ 的 VS 代码,并且我正在使用 cl.exe 作为我的 c 编译器。即使以为我已经在配置设置中编辑了路径,我也在 include 语句中遇到了错误。 我尝试添加完整路径,然后它们消失了,但我仍然收到编译错误。任何解决方案或教程可以帮助我解决这个问题?
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/statement.h>
#include <iostream>
#include <mysql_connection.h>
#include <mysql_driver.h>
using namespace std;
int main() {
try {
// Establish a connection to the MySQL server
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "username", "password");
// Create the sensor_temp_data table
sql::Statement *stmt = con->createStatement();
stmt->execute("CREATE TABLE sensor_temp_data ("
"measurement_id INT NOT NULL AUTO_INCREMENT,"
"sensor_id INT,"
"unit_of_measurement VARCHAR(50),"
"timestamp TIMESTAMP,"
"temperature_value FLOAT,"
"PRIMARY KEY (measurement_id)"
")");
delete stmt;
delete con;
} catch(const sql::SQLException& e) {
std::cout << "SQL Error: " << e.what() << std::endl;
}
return 0;
}
我尝试观看在线教程,但无济于事。
答: 暂无答案
评论