@test
public void add() throws exception {
long start = system.currenttimemillis();
for(int i=0;i<1000;i++){
customer customer = new customer();
customer.setname("普通一条条插入 "+ i);
customer.setage(15);
customer.setcerono("000000000000"+ i);
customer.setcerotype(2);
customer.setsex(1);
int result = customerdao.add(customer);
}
system.out.println("耗时 : "+(system.currenttimemillis() - start));
}
@test
public void batchinsert() throws exception {
map<string,object> param = new hashmap<string,object>();
list<customer> list = new arraylist<customer>();
for(int i=0;i<1000;i++){
customer customer = new customer();
customer.setname("批量插入" + i);
customer.setage(15);
customer.setcerono("111111111111"+i);
customer.setcerotype(2);
customer.setsex(1);
list.add(customer);
}
param.put("list",list);
long start = system.currenttimemillis();
int result = customerdao.batchinsert(param);
system.out.println("耗时 : "+(system.currenttimemillis() - start));
}
两种都进行插入1000条测试
由于我没有用连接池等等原因,在插入了700多条的时候 junit直接挂了,
cause: org.apache.ibatis.executor.executorexception: error selecting key or setting result to parameter object.
cause: com.mysql.jdbc.exceptions.jdbc4.mysqlnontransientconnectionexception:
data source rejected establishment of connection, message from server: "too many connections"