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)");
相关推荐
oldking呐呐6 小时前
MySQL从建库到删库跑路 -- 4.表的操作
后端·mysql
qq_283720057 小时前
Python3 模块精讲:pymysql(第三方)- 连接 MySQL
mysql·adb·pymysql
czlczl200209257 小时前
MySQL 性能优化:前缀索引(Prefix Index)深度解析
数据库·mysql·性能优化
y = xⁿ8 小时前
MySQL八股知识合集
android·mysql·adb
用户805533698039 小时前
现代Qt开发教程(新手篇)1.10——进程
c++·qt
vegetablesssss9 小时前
VTK切割图
c++·qt·vtk
计算机安禾9 小时前
【Linux从入门到精通】第33篇:数据库MySQL/MariaDB安装与基础调优
linux·数据库·mysql
tang&10 小时前
【MySQL】索引创建与B+树原理:MySQL性能优化的核心一课
b树·mysql·性能优化
sitellla10 小时前
MySQL 入门:最流行的开源关系型数据库介绍
数据库·mysql·其他·开源
2301_8084143810 小时前
MySQL表的约束
数据库·mysql