|
package com.kevin.stresstest;
import java.sql.*;
public class BigTableJoinTest {
/**
* @param args
*/
public static void main(String[] args) {
Connection conn = null;
try {
Class.forName(”com.mysql.jdbc.Driver”).newInstance();
// 建立到MySQL的连接
conn = DriverManager.getConnection(
“jdbc:mysql://localhost:8306/test”, “root”, “”);
Statement stmt;
PreparedStatement pstmt;
// ResultSet res;
for (int i = 1; i <= 100000; i++) {
// stmt.executeUpdate(”insert into user(username)”);
stmt = conn.createStatement();
conn.setAutoCommit(false);
for(int j=0;j<1000;j++){
String username=”u”+i;
String email=”email”+i;
String pass = “p”+i;
String addr= “addr_”+i;
String homepage=”home_”+i;
String tel=”tel_”+i;
Timestamp ts= new java.sql.Timestamp(System.currentTimeMillis());
// String sql=”insert into user(username,email,password,regdate) values(’”+username+”‘,’”+email+”‘,’”+pass+”‘,’”+ts+”‘)”;
for(int k=0;k<20;k++){
int votevalue=0;
if(k%3==1) votevalue = 1;
String sql=”insert into customer(CUSTOMER_NAME,TEL,BUSINESS,DATE_ADDED,EMAIL) values(’客户”+i+”‘,’13588888888′,’经营’,now(),’”+email+”‘)”;
stmt.addBatch(sql);
}
// String sql=”insert into user_ext(user_id,address,homepage,tel) values(”+i+”,’”+addr+”‘,’”+homepage+”‘,’”+tel+”‘)”;
// stmt.addBatch(sql);
i++;
if(i%2900==1) {
Thread.sleep(200);
System.out.println(”"+i);
}
}
i–;
int[] updateCounts = stmt.executeBatch();
// System.out.println(updateCounts);
conn.commit();
stmt.close();
// pstmt = conn.prepareStatement(”insert into user(username,email,password,regdate) values(?,?,?,?)”);
// pstmt.setString(1, “u” + i);
// pstmt.setString(2, “email” + i);
// pstmt.setString(3, “p” + i);
// pstmt.setTimestamp(4, new java.sql.Timestamp(System.currentTimeMillis()));
// pstmt.execute();
// pstmt.close();
}
System.out.println(”done”);
// if(res.next())
// {
// int exID = res.getInt(”id”);
// duplicateSn = true;
//
// }
// res.close();
} catch (Exception ex) {
System.out.println(”Error : ” + ex.toString());
} finally {
if (conn != null)
try {
conn.close();
} catch (Exception e) {
}
}
}
public static void insertUserExt(Connection conn){
}
}
Share and Enjoy:
These icons link to social bookmarking sites where readers can share and discover new web pages.
 Loading ...
喜欢本文?马上订阅IdeaGrace's Blog吧。
相关日志:
Nutch的使用 CakePHP入门教程文章 脑筋急转弯 jquery的ajax用法 PHP开发安全浅谈
|
You must be logged in to post a comment.