Qt传入参数到mysql语句

试过两种方法都成功了

复制代码
方法1:

使用bool QSqlQuery::preparevoid QSqlQuery::bindValue传入参数,然后再使用bool QSqlQuery::exec()

执行Mysql语句

c 复制代码
QSqlDatabase db //数据库
QSqlQuery result(db); // 基于已连接的数据库db建立 QSqlQuery 对象
QString strTime; //要传入的Qstring字符串:时间信息

result.prepare("insert into test_table values(13,:str)");
result.bindValue(":str",strTime);
bool result_successed =result.exec();
复制代码
方法2:

'"+变量名+"'这种格式直接写在mysql语句里

c 复制代码
result.exec("insert into test_table values(11,'"+strTime+"',12354,28)");
相关推荐
sim20207 小时前
systemctl isolate graphical.target命令不能随便敲
linux·mysql
不会c嘎嘎7 小时前
QT中的常用控件 (二)
开发语言·qt
lkbhua莱克瓦248 小时前
进阶-索引3-性能分析
开发语言·数据库·笔记·mysql·索引·性能分析
IT教程资源C9 小时前
(N-089)基于springboot网上订餐系统
mysql·springboot订餐系统
IT教程资源D10 小时前
[N_083]基于springboot毕业设计管理系统
mysql·springboot毕业设计
韦东东10 小时前
DeepSeek:R1本地RAG 问答: 功能新增,附 六大关键技术优化路径参考
数据库·mysql
赵渝强老师10 小时前
【赵渝强老师】MySQL的数据约束
数据库·mysql
半部论语10 小时前
MySQL 主机被封问题详解:原因、解除方法与预防策略
数据库·mysql
宠..11 小时前
优化文件结构
java·服务器·开发语言·前端·c++·qt
高溪流12 小时前
1.MySql概念讲解 及 MySql安装教程
数据库·mysql