c++ mysql连接器从字符串中选择id

标签 c++ mysql

我正在尝试从 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'");

我觉得它工作正常

最佳答案

res = stmt->executeQuery(std::string("SELECT ID FROM IPs Where IP_Address = '"+ GETI +'\'').c_str());

关于c++ mysql连接器从字符串中选择id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13653897/

相关文章:

c# - 加密c#和mysql之间的数据流量

java - 从 GWT 进行 jdbc 调用的正确方法?

c++ - 如何强制 MinGW 使用 tr1 命名空间?

c++ - OpenCV 快速垫元素​​和邻居访问

c++ - std::unordered_map 自定义值类型,operator[]

c++ - OpenCV 与 Qt 集成

c++ - 将 NT 文件时间转换为 Win32 时间

mysql - 在mysql选择查询中需要正则表达式

PHP -\u00f8 (ø) 变为 u00f8

mysql - 为具有相同 where 条件的多个查询编写单个查询