Qt传入参数到mysql语句

试过两种方法都成功了

复制代码
方法1:

使用bool QSqlQuery::prepare和void 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)");
相关推荐
小此方8 小时前
Re:Mysql数据库基础篇(八):详细讲解复合查询、多表查询、自连接、多行、多列子查询与合并查询
数据库·mysql
听风吹等浪起9 小时前
第26章:ViT+InceptionDW+FocalLoss改进|CT骨折影像二分类完整Pytorch实现(含PyQt5推理GUI)
pytorch·qt·分类
smile_life_9 小时前
MySQL 设置 防止账户被暴力破解
数据库·mysql
ShineWinsu9 小时前
对于Qt:QRadioButton常见属性以及QButtonGroup的解析
数据库·c++·qt·microsoft·gui·qradiobutton·qbuttongroup
滕州市燕猫虎计算机科技工作室个体工商户9 小时前
MySQL、MVCC、多版本并发控制
数据库·mysql·mvcc·数据库事务
Decay__11 小时前
09_MySQL 闪回与时间点恢复 —— binlog 回放、mysqlbinlog、PITR 与误删恢复
运维·数据库·sql·mysql·架构
太理摆烂哥11 小时前
MySQL用户管理
数据库·mysql
sycmancia13 小时前
Qml——Image和AnimatedImage使用
qt
梦影_13 小时前
MySQL进阶教程(五)—— SQL调优(下)
android·大数据·数据库·后端·sql·mysql·database
John_Hui15 小时前
Windows 10 安装版本:mysql-8.1.0-winx64.zip
数据库·windows·mysql