惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
C
Check Point Blog
J
Java Code Geeks
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
量子位
Google DeepMind News
Google DeepMind News
I
InfoQ
The GitHub Blog
The GitHub Blog
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
V
V2EX
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
小众软件
小众软件
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
IT之家
IT之家

博客园 - bitwoods

Linux驱动开发:内核模块堆叠(1) Linux驱动开发:内核模块与普通应用的区别 Linux驱动开发:从一个最简单的模块开始 glog编译报错解决 阿里云Ubuntu服务器优化 linux c++程序使用MD5 串口AT与数据的混杂接收处理 蓝牙Mesh简介(一)设备标识:UUID和Mesh地址 MT7621 openWrt插件操作GPIO(mmap) adblock plus 您的地区不可用 OpenWRT 修改固件默认显示中文 OpenWRT:插件自启动 OpenWRT编译时修改时区与主机名 SC200L Android10启动和关机修改 ILI9881D驱动 ubuntu20.04 微信和迅雷安装包 开启power management功能有坑,ESP32串口频繁出现UART_BREAK中断 MAC地址与字符串的相互转化 ESP32音频开发板ESP32-Korvo V1.1踩坑
c++ prepareStatement使用like查询语句的方式
bitwoods · 2024-07-24 · via 博客园 - bitwoods

代码

sql::PreparedStatement  *read_stmt;
read_stmt = pconn->prepareStatement("SELECT * from `user` WHERE level LIKE ? ");
//1
sql::SQLString searchPattern(("%" + key + "%").c_str());
read_stmt->setString(1, searchPattern);
//2
//std::string kk = "%"+key+"%'";
//read_stmt->setString(1, kk);

auto_ptr<ResultSet> pres(read_stmt->executeQuery());
int n = pres->rowsCount();
LOG_INFO << "rows: " << n;
if(n > 0){
  while (pres->next())
  {
    //取出数据
  }
}
delete read_stmt;

注意,在某些情况下,如果查询始终未生效,请检查查询参数key的右侧是否包含多个'\0'或者其它不可见字符;