资源简介
使用java程序制造大量的数据,直接写入数据库,代码简单易懂
代码片段和文件信息
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.junit.Test;
public class BatchMysql {
@Test
public static void batchInsert() throws ClassNotFoundException SQLException{
long start = System.currentTimeMillis();
Class.forName(“com.mysql.jdbc.Driver“);
Connection connection = DriverManager.getConnection(
“jdbc:mysql://127.0.0.1:3306/wemall?useServerPrepStmts=false&rewriteBatchedStatements=true“
“root“ “123456“);
connection.setAutoCommit(false);
PreparedStatement pstm = connection
.prepareStatement(“INSERT INTO wemall_user(idaddtimedeleteStatusMSNQQWWaddressavailableBalancebirthdayemailfreezeBlancegoldintegrallastLoginDatelastLoginIploginCountloginDateloginIpmobile‘password‘reportsexstatustelephonetrueNameuserNameuserRoleuser_creditphoto_idstore_idqq_openidsina_openidstore_quick_menuparent_idyearsarea_idtokensalesman_idlogoUrlweixinzfbidentityIdreferrerIdValidateCodeValidateTimecommissionRateagentIdproviderIdsalesmanIdlegal_IdCardlegal_namelegal_telephonenumberlegal_business_licencebuyersellernametl_useridbanned_statusdepositdeposit_statedeposit_timeTL_uuid) VALUES(????????????????????????????????????????????????????????????)“);
for (int i = 132001000; i < 133001000; i++) {//100万条数据
pstm.setInt(1 i);
pstm.setString(2 “20170104“);
pstm.setString(3 ““);
pstm.setString(4 “85236547@qq.com“);
pstm.setString(5 “856985472“);
pstm.setString(6 “wwww.dkjf.com“);
pstm.setString(7 “广州市“);
pstm.setString(8 “9620“);
pstm.setString(9 “19930104“);
pstm.setString(10 “86523654@ww.com“);
pstm.setString(11 “12“);
pstm.setString(12 “0“);
pstm.setString(13 “2“);
pstm.setString(14 “20170104“);
pstm.setString(15 “0:0:0:0:0:0:0:1“);
pstm.setString(16 “1“);
pstm.setString(17 “20170104“);
pstm.setString(18 “0:0:0:0:0:0:0:1“);
pstm.setString(19 “15236547852“);
pstm.setString(20 “e10adc3949ba59abbe56e057f20f883e“);
pstm.setString(21 “0“);
pstm.setString(22 “0“);
pstm.setInt(23 1);
pstm.setString(24 “156022876281“);
pstm.setString(25 “0“);
pstm.setInt(26 i);
pstm.setString(27 “BUYER“);
pstm.setString(28 “0“);
pstm.setInt(29 1);
pstm.setInt(30 32818);
pstm.setString(31 “123“);
pstm.setString(32 ““);
pstm.setString(33 ““);
pstm.setInt(34 i);
pstm.setString(35 “0“);
pstm.setInt(36 4521984);
pstm.setString(37 “f5fbd4d9a77f471c9d376f4440d340b
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 461 2017-06-09 11:30 MysqlDemo\.classpath
文件 385 2017-06-09 11:10 MysqlDemo\.project
文件 629 2017-06-09 11:10 MysqlDemo\.settings\org.eclipse.jdt.core.prefs
文件 3889 2017-06-09 18:17 MysqlDemo\bin\BatchMysql.class
文件 4791 2017-06-09 17:43 MysqlDemo\bin\mysqltest.class
文件 4210 2017-06-09 18:17 MysqlDemo\src\BatchMysql.java
文件 6882 2017-06-09 17:43 MysqlDemo\src\mysqltest.java
目录 0 2017-06-09 11:10 MysqlDemo\.settings
目录 0 2017-06-09 18:05 MysqlDemo\bin
目录 0 2017-06-09 18:05 MysqlDemo\src
目录 0 2017-06-09 11:10 MysqlDemo
----------- --------- ---------- ----- ----
21247 11
评论
共有 条评论