【问题标题】:Connection failing with MySQL using Poco使用 Poco 与 MySQL 连接失败
【发布时间】:2014-03-27 10:36:45
【问题描述】:

我在 C++、Ubuntu (12.04) 和 MySQL 5.5 x64 上使用 Poco(1.5.2 版)。

我尝试使用以下代码连接到 MySQL:

#include <iostream>

#include <Poco/Data/MySQL/MySQLException.h>
#include <Poco/Data/MySQL/Connector.h>
#include <Poco/Data/SessionFactory.h>

using namespace std;

int main()
{
    Poco::Data::MySQL::Connector::registerConnector();
    try
    {
        string chaine = "host=localhost;user=root;password=mypassword;";
        Poco::Data::Session test(Poco::Data::SessionFactory::instance().create(Poco::Data::MySQL::Connector::KEY, chaine));
    }
    catch(Poco::Data::MySQL::MySQLException& e)
    {
        cout << "Error: " << e.what() << endl;
    }
    return 0;
}

但是有一个 MySQLException:

错误:MySQL

这是什么意思?有没有人可以帮助我?

谢谢!!

编辑:好的,这个错误是一个错误的库链接:p 我使用了一个来自错误 MySQL 版本的库 ^^

【问题讨论】:

  • 你应该回答你自己的问题(或删除它)。

标签: c++ mysql poco-libraries


【解决方案1】:

使用 displayText() 获取详细的异常信息:

catch(Poco::Data::MySQL::MySQLException& e)
{
    std::cout << "Error: " << e.displayText() << '\n';
}

【讨论】:

    【解决方案2】:

    正如我在第一条消息中所说,该错误是错误的库链接。我使用了一个来自不良 MySQL 版本的库 ^^

    我希望这篇文章能帮助遇到同样问题的人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 2012-02-22
      • 1970-01-01
      • 2019-03-01
      • 1970-01-01
      • 2016-03-19
      相关资源
      最近更新 更多