アナログ挿入1000万件
3308 ワード
/**
* part
*/
public static void insertPart(){
Connection conn= getConnetion();
PreparedStatement pstmt=null;
try {
pstmt=conn.prepareStatement("insert into part(part_num,part_desc) values(?,?)");
for(int i=0;i<10;i++){
pstmt.setString(1, String.valueOf((int)(Math.random() * 1000)));
pstmt.setString(2, " "+i);
pstmt.executeUpdate();
}
System.out.println(" !");
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
pstmt.close();
close(conn);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* vendor
*/
public static void insertVendor(){
Connection conn= getConnetion();
PreparedStatement pstmt=null;
try {
pstmt=conn.prepareStatement("insert into vendor(vendor_num,vendor_name) values(?,?)");
for(int i=0;i<10;i++){
pstmt.setString(1, String.valueOf((int)(Math.random() * 1000)));
pstmt.setString(2, " "+i);
pstmt.executeUpdate();
}
System.out.println(" !");
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
pstmt.close();
close(conn);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* vendor
*/
public static void insertParven(){
Connection conn= getConnetion();
Statement stmt1=null;
Statement stmt2=null;
PreparedStatement pstmt=null;
ResultSet rs1=null;
ResultSet rs2=null;
List list1=new ArrayList();
List list2=new ArrayList();
try {
pstmt=conn.prepareStatement("insert into parven(part_num,vendor_num,PART_AMOUNT)values(?,?,?)");
stmt1=conn.createStatement();
stmt2=conn.createStatement();
rs1=stmt1.executeQuery("select p.part_num from part p");
rs2=stmt2.executeQuery("select v.vendor_num from vendor v");
while(rs1.next()){
list1.add(rs1.getString(1));
}
while(rs2.next()){
list2.add(rs2.getString(1));
}
String partnum="";
String vendornum="";
// vendor 1000 , 1000 ,1 1143379 , 15
for(int i=0;i<list1.size();i++){
for(int j=0;j<list2.size();j++){
for(int k=0;k<100000;k++){
partnum=(String)list1.get(i);
vendornum=(String)list2.get(j);
pstmt.setString(1, partnum);
pstmt.setString(2, vendornum);
pstmt.setInt(3, (int)(Math.random() * 1000));
pstmt.executeUpdate();
}
}
}
System.out.println(" !");
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
pstmt.close();
rs2.close();
rs1.close();
stmt1.close();
close(conn);
} catch (SQLException e) {
e.printStackTrace();
}
}
}