淘先锋技术网

首页 1 2 3 4 5 6 7

import java.lang.*;

import java.sql.*;

public class InsertTestMysql{

public static void main(String [] args){

java.util.Date now_start = new java.util.Date();

long start_time=now_start.getTime();

int st = 100000;

String str,info;

String db="org.gjt.mm.mysql.Driver";

String host="jdbc:mysql://192.168.1.35/test";

String user="root";

String passwd="root";

Connection con=null;

try{

Class.forName(db).newInstance();

}

catch(Exception e){

System.out.println("加载驱动失败:"+db);

}

try{

con=DriverManager.getConnection(host,user,passwd);

con.setAutoCommit(false);//关闭事务自动提交

for (int i=1;i<=st;i++){

info = "这条记录是第=";

info = info.concat(java.lang.Integer.toString(i));

str = "insert into test (id,txt) values(?,?);";

PreparedStatement pstmt = con.prepareStatement(str);

pstmt.setInt(1,i);

pstmt.setString(2,info);

pstmt.executeUpdate();

}

con.commit();//语句执行完毕,提交本事务

con.close();

}

catch(Exception e) {

System.out.println(e);

}

java.util.Date now_end = new java.util.Date();

long end_time=now_end.getTime();

long use_time=end_time-start_time;

System.out.println("<>");

System.out.println("\n<>");

}

}