
正文
MySQL
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
要疯了,怎样用多线程向MYSQL数据库中写入数据
#include QCoreApplication
#include "thread.h"
#include QVector
#include QDebug
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QVectorThread* vector;
Thread *thread;
//创建多个线程,并start
for(int i=0;i10;i++){
thread=new Thread;
vector.append(thread);
thread-set(i);
thread-start();
}
//等待所有线程执行完,然后删除线程
foreach(thread,vector){
thread-wait();
}
foreach(thread,vector){
delete thread;
}
return a.exec();
}
相关问答
Q1: mysql如何导入数据?
如何导入.sql文件到mysql中
首先:建立数据库,用这个命令:create database dbname; 其中dbname是数据库名称
C:\mysql\binmysql -u 用户名 -p 数据库名 c:/test.sql
中间的空格是一个空格位。
例如:C:\Program Files\MySQL\binmysql -u root -p myrosz c:/myro.sql
Enter password: ****
稍等一会,就可以导入数据表。
Q2: 换行和首行缩进如何写入MYSQL数据库
最简单的就是按四个空格键,要来点技术的就从菜单栏里格式的下拉菜单找段落,然后打开了段落的对话框就能看见了,我现在用的事2010,所以以上步骤是凭记忆来的。
Q3: MySQL数据库 写入大量数据如何实现
//最快的方法 10000记录 23MS
public static void insert() {
// 开时时间
Long begin = new Date().getTime();
// sql前缀
String prefix = "INSERT INTO tb_big_data (count, create_time, random) VALUES ";
try {
// 保存sql后缀
StringBuffer suffix = new StringBuffer();
// 设置事务为非自动提交
conn.setAutoCommit(false);
// Statement st = conn.createStatement();
// 比起st,pst会更好些
PreparedStatement pst = conn.prepareStatement("");
// 外层循环,总提交事务次数
for (int i = 1; i = 100; i++) {
// 第次提交步长
for (int j = 1; j = 10000; j++) {
// 构建sql后缀
suffix.append("(" + j * i + ", SYSDATE(), " + i * j
* Math.random() + "),");
}
// 构建完整sql
String sql = prefix + suffix.substring(0, suffix.length() - 1);
// 添加执行sql
pst.addBatch(sql);
// 执行操作
pst.executeBatch();
// 提交事务
conn.commit();
// 清空上一次添加的数据
suffix = new StringBuffer();
}
// 头等连接
pst.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
// 结束时间
Long end = new Date().getTime();
// 耗时
System.out.println("cast : " + (end - begin) / 1000 + " ms");
}







