用java在mysql中随机插入9000 000条数据
2024-10-18 16:18:13
package query; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
import java.util.jar.Attributes.Name; public class query {
public static void main(String[] args) {
// 驱动程序名
String driver = "com.mysql.jdbc.Driver"; // URL指向要访问的数据库名9million
String url = "jdbc:mysql://127.0.0.1:3306/9million"; // MySQL配置时的用户名
String user = "root"; // MySQL配置时的密码
String password = ""; try {
// 加载驱动程序
Class.forName(driver); // 连续数据库
Connection conn = DriverManager.getConnection(url, user, password); if (!conn.isClosed())
System.out.println("Succeeded connecting to the Database!"); // statement用来执行SQL语句
Statement statement = conn.createStatement(); // 要执行的SQL语句
for (int i= 0; i <= 9000 000; i ++){
String rdname = randomString(8);
int id = i;
System.out.println(rdname);
//丢了引号会出错,找不到collumn“ID”或者“rdname”
int型的可以不用加,但是string类型的必须加。
有空研究下底层实现
String sqll = "insert into testdata (id,name) values ('"+id+"','"+rdname+"')"; statement.execute(sqll);
}
conn.close(); } catch (ClassNotFoundException e) { System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } /**
* 产生随机字符串
* */
private static Random randGen = null;
private static char[] letters = null;
public static final String randomString(int length) {
if (length < 1) {
return null;
}
if (randGen == null) {
randGen = new Random();
// numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" +
// "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
letters = ("abcdefghijklmnopqrstuvwxyz").toCharArray();
//numbersAndLetters = ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
}
char [] randBuffer = new char[length];
for (int i=0; i<randBuffer.length; i++) {
randBuffer[i] = letters[randGen.nextInt(25)];
//randBuffer[i] = numbersAndLetters[randGen.nextInt(35)];
}
return new String(randBuffer);
} }
遇到的问题:
第一次插入的时候,只能显示1000条记录
navicat for mysql ,默认查看表是显示前1000条。工具=》选项=》数据&网格=》限制记录,这里可以修改默认值。
最新文章
- SSM框架总结(1)
- 解压版mysql安装
- Myeclipse常用快捷键
- ubuntu 上安装 NASM 汇编开发工具
- url重写后发布出错问题
- 长理ACM 14-星期几(谌海军)
- Spring 事务配置5种方式
- 清除SQL Server 2008中登陆时的历史记录
- 关于ArrayList线程安全解决方案
- Java 获取字符串中第N次出现的字符位置
- web.xml 3.0头部模板
- 对Spring.Net+NHibenate+Asp.Net Mvc+Easyui框架的个人认识
- #if和#ifdef区别
- [2016-07-15]nuget包管理器控制台下的powershell脚本介绍
- 《ASP.NET Core In Action》读书笔记系列二 ASP.NET Core 能用于什么样的应用,什么时候选择ASP.NET Core
- licode测试
- Networked Graphics: Building Networked Games and Virtual Environments (Anthony Steed / Manuel Fradinho Oliveira 著)
- git push 使用
- 【poj3693】 Maximum repetition substring
- oracle只导出触发器
热门文章
- 【JQuery NoviceToNinja系列】目录
- codeforces 463D Gargari and Permutations(dp)
- HDU 4576 Robot(概率dp)
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 2(Big Number)
- 动态调用webservice 接口
- .bat后台运行
- RadioButtonList js获取选择的项
- 【poj3358】消因子+BSGS 或 消因子+欧拉定理 两种方法
- skip list
- 有N个大小不等的自然数(1--N),请将它们由小到大排序。要求程序算法:时间复杂度为O(n),空间复杂度为O(1)。