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)");
相关推荐
deviant-ART3 分钟前
MySQL里的三个concat函数
数据库·mysql
H_老邪13 分钟前
1044 - Access denied for user ‘root‘@‘%‘ to database ‘nacos‘
数据库·mysql
大智兄25 分钟前
128.配置qt(交叉)编译的路径---解决无法编译的问题
qt
凭X而动1 小时前
MySQL 5.7.44 部署
数据库·mysql·部署
Adorable老犀牛1 小时前
MySQL Server Exporter:Prometheus 监控 MySQL/MariaDB 指南
mysql·prometheus·mariadb
范什么特西2 小时前
重点:mybatis注意细节
java·mysql·mybatis
swordbob3 小时前
MySQL和Oracle关于读未提交的区别
数据库·mysql·oracle
林九生3 小时前
【实用技巧】MySQL 绿色版一键路径更新脚本详解 —— update_path.bat 深度解析
android·数据库·mysql
野生技术架构师3 小时前
从 B+ 树到应用层分表:MySQL 海量数据架构解析
数据库·mysql·架构
Amnesia0_03 小时前
MySQL的事务
数据库·mysql