0

我正在尝试从 IP_Address = [string] 的表中选择 ID

我将从另一个函数中获取 IP 地址

    std::string GetIP(){
    return IP;
    }

  sql::Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  sql::ResultSet *res;
  sql::PreparedStatement *pstmt;

  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1.:3306", "root", "password");
  con->setSchema("Test");
stmt = con->createStatement();
string GETI = "84.54.584.6"; // will be GetIP()
res = stmt->executeQuery("SELECT ID FROM IPs Where IP_Address = '"+ GETI +"'");
while (res->next()) {
cout << "id = " << res->getInt(1); 
}
delete res;
delete stmt;
delete con;

我在 Visual Studio 的错误列表中没有收到任何错误

但是当我运行应用程序时它不显示值并且应用程序崩溃

当我尝试

res = stmt->executeQuery("SELECT ID FROM IPs Where IP_Address = '84.54.584.6'");

我让它工作正常

4

1 回答 1

1
res = stmt->executeQuery(std::string("SELECT ID FROM IPs Where IP_Address = '"+ GETI +'\'').c_str());
于 2012-11-30T22:44:57.330 回答