MySQL C++ Connector UPDATE

MySQL C++ Connector UPDATE

本文关键字:UPDATE Connector C++ MySQL      更新时间:2023-10-16

我在使用 MySQL C++ 连接器时遇到问题...我的问题是我有一个查询:UPDATE characters SET name = 'myNameIs' WHERE characregistra = 'MyguidIs'字符是表,命名一列,字符也是。当我在字符列中找到值"MyguisIs"时,我尝试将 myNameIs 值放入名称中。它可以工作,但如果没有try{]catch{],它就会崩溃。我试图用sql::SQLException得到错误,但没办法,打印什么都没有...提前谢谢。

编辑:忘记输入代码:

void renameCharac(std::string guid, std::string pseudo)
{
    try{
        sql::Statement *declaration;
        declaration = connection->createStatement(); // Connection is declared
        declaration->executeQuery("UPDATE characters SET name = '" + pseudo + "' WHERE characregistra = '" + guid + "'");
        delete declaration;
    }
    catch (sql::SQLException e)
    {
        std::cout << e.what();
    }
}

最后我是这样做的:

void renameCharac(std::string guid, std::string pseudo)
{
        sql::Statement *declaration;
        declaration = connection->createStatement();
        declaration->executeUpdate("UPDATE characters SET name = '" + pseudoChoisi + "' WHERE characregistra = '" + guid + "'");
        delete declaration;
}

它有效。