前几天刚把一个小实验的程序写完了,今天写的是在搞测试时如何插入100万行的数据,本程序的插入数据的次数可以调节,如果机子差调小一些就可以了。
这一点代码是建库和建表,
以及查询语句。
---创建名为mb得库
create database mb
--使用mb库
use mb
--查询表JobInfo
select * from JobInfo
--删除表JobInfo
drop table JobInfo
--创建表JobInfo
create table JobInfo(
id int not null , --用户id整形不能为空
name varchar(10), --用户名字类型为varchar大小为10
age varchar(3), --用户年龄字类型为varchar大小为3
laborage varchar(10) --用户月薪类型为varchar大小为10
)
下面的是程序段,我的程序写的很差因为没有浪费过多的时间去调试,
让程序跑的更好,如果大家觉的那里需要修改尽管给我留言,我在这里先谢谢了兄弟。o(∩_∩)o...哈哈
本程序的名字为InsertDate
import java.util.* ;
import java.sql.* ;
public class InsertDate {
private static char chA ;
private static char ch1 ;
private static char ch2 ;
private static char ch3 ;
private static int age ;
private static int price ;
public static void main(String args[]){
try {
//连接数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection cn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=mb","sa","1234") ;
Statement st = cn.createStatement() ;
//产生26个字母的写随机数
int j = 0 ;
String NchA = " " ;
String Nch1 = "" ;
String Nch2 = "" ;
String Nch3 = "" ;
String Nage = "" ;
String SQLString = "";
//定义插入次数
while(j < 10000){
//定义随机数循环次数
for (int i = 0; i<100; i++){
chA = ((char)((int)(Math.random()*90))) ;
ch1 = ((char)((int)(Math.random()*123))) ;
ch2 = ((char)((int)(Math.random()*123))) ;
ch3 = ((char)((int)(Math.random()*123))) ;
age = ((int)(Math.random()*60)) ;
price = ((int)(Math.random()*800)*10);
//获得名字中的大写
if(chA >65 && chA <90)
{
NchA = ""+chA ;
}
//获得名字中的第一个小写
if(ch1 >96 && ch1 <123){
Nch1 = ""+ch1 ;
}
//获得名字中的第二个小写
if(ch2 >96 && ch2 <123){
Nch2 = ""+ ch2 ;
}
//获得名字中的第三个小写
if(ch3 >96 && ch3<123){
Nch3 = "" + ch3 ;
}
//获得年龄最小18岁最大60岁
if(age >18 && age <60){
Nage = "" +age ;
}
//定义SQL查询语句
SQLString ="insert into JobInfo (id ,name ,age ,laborage)values ("+ j+ " ,' "+NchA+Nch1+Nch2+Nch3+ "' , '"+Nage+"' , '"+price+"' ) " ;
System.out.println (j) ;
}
//执行查询
st.executeUpdate(SQLString) ;
//记数器---根据此数选择是不是结束程序
j++ ;
}
}
catch (Exception ex) {
ex.printStackTrace() ;
}
}
}
这段程序就告一段落了,接下来我要写的是如何从数据库中读取数据,从中将数据提取出来存入文本文件。o(∩_∩)o...哈哈 继续加油俺 呵呵