【问题标题】:mysql cpp connector throwing UnknownException while connectingmysql cpp连接器在连接时抛出UnknownException
【发布时间】:2011-12-25 09:07:43
【问题描述】:

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

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

【问题讨论】:

    标签: c++ mysql exception database-connection


    【解决方案1】:

    在将 serverusernamepassword 等所有连接参数的 string 更改为 SQLString 后,此方法有效。

    这就像一个魅力。

    【讨论】:

    • 我尝试了这个解决方案但没有成功。你还做了什么让它发挥作用?
    猜你喜欢
    • 1970-01-01
    • 2019-09-30
    • 2015-05-28
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    相关资源
    最近更新 更多