gpt4 book ai didi

c++ - 连接时mysql cpp连接器抛出UnknownException

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:00:38 25 4
gpt4 key购买 nike

我正在使用 mysql 库连接到我的数据库 (mysql) 以在连接后检索数据。检查我的服务是否正常运行。

以下是执行连接任务的代码部分..

// Specify our connection target and credentials
const string server = "tcp://127.0.0.1:3306";
const string username = "root";
const string password = "";// No password - thanks, WAMP Server!

// Try to get a driver to use to connect to our DBMS
try {
driver = get_driver_instance();
if( driver == NULL )
throw SQLException("Null driver instance returned.");
}
catch (SQLException e) {
cout << "Could not get a database driver. Error message: " << e.what() << endl;
return -3;
}

// Try to connect to the DBMS server
try {
dbConn = driver->connect(server, username, password);
}
catch (sql::SQLException e) {
cout << "Could not connect to database. Error message: " << e.getSQLStateCStr() << " Error Code: " << e.getErrorCode() << endl;
cout << "Could not connect to database. Error: " << e.what() << endl;
return -1;
}

它编译得很好,但给出了一个带有未知调试信息的未知异常。像这样的东西。请帮忙。

enter image description here

最佳答案

这在将所有连接参数的 string 更改为 SQLString 后有效,例如 serverusername密码

这就像一个魅力。

关于c++ - 连接时mysql cpp连接器抛出UnknownException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8066599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com