简体   繁体   English

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

[英]mysql cpp connector throwing UnknownException while connecting

I am using mysql library to connect to my database (mysql) to retrieve the data after connecting. 我正在使用mysql库连接到我的数据库(mysql),以在连接后检索数据。 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. 请帮忙。

在此处输入图片说明

This worked after changing the string to SQLString for all the connection params like server , username and password . 在将所有连接参数(例如serverusernamepasswordstring更改为SQLString后,此方法有效。

This worked out like a charm. 这像一个魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM