mysql cpp 连接器在连接时抛出 UnknownException

发布于 2024-12-14 12:08:55 字数 1152 浏览 0 评论 0原文

我正在使用 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;
}

它编译良好,但给出了未知的异常和未知的调试信息。像这样的东西。请帮忙。

在此处输入图像描述

I am using mysql library to connect to my database (mysql) to retrieve the data after connecting. Checked that my services are running properly.

Following is the part of code that does the connecting task..

// 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;
}

It compiles well but gives an unknown exception with unknown debug info. Something like this. Please help.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2024-12-21 12:08:55

将所有连接参数(如服务器、用户名和密码)的字符串更改为 SQLString 后,此方法有效。

这就像一个魅力。

This worked after changing the string to SQLString for all the connection params like server, username and password.

This worked out like a charm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文