插入数据失败
@Test
public void testBatch(){
SqlSession sqlSession=null;
try{
long st=new Date().getTime();
List list=new ArrayList();
sqlSession=MyBatisUtils.openSession();
for (int i=1;i<1000;i++) {
for (int j=1;j<10000;j++){
Student student = new Student();
student.setRegNo(1234);
student.setName("小王");
student.setSex("男");
student.setAge(17);
student.setMajor("Java");
student.setGrade("2020");
list.add(student);
}
}
sqlSession.insert("student.batchStudent",list);
sqlSession.commit();
long et=new Date().getTime();
System.out.println("时间;"+(et-st)+"毫秒");
}catch (Exception e){
if (sqlSession!=null){
sqlSession.rollback();
}
throw e;
}finally {
MyBatisUtils.closeSession(sqlSession);
}
}
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:448)
at java.lang.StringBuilder.append(StringBuilder.java:136)
at java.lang.StringBuilder.append(StringBuilder.java:76)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:484)
at java.lang.StringBuilder.append(StringBuilder.java:166)
at java.util.StringJoiner.add(StringJoiner.java:185)
at org.apache.ibatis.scripting.xmltags.DynamicContext.appendSql(DynamicContext.java:65)
at org.apache.ibatis.scripting.xmltags.ForEachSqlNode$PrefixedContext.appendSql(ForEachSqlNode.java:204)
at org.apache.ibatis.scripting.xmltags.ForEachSqlNode$FilteredDynamicContext.appendSql(ForEachSqlNode.java:161)
at org.apache.ibatis.scripting.xmltags.StaticTextSqlNode.apply(StaticTextSqlNode.java:30)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode$$Lambda$13/128359175.accept(Unknown Source)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
at org.apache.ibatis.scripting.xmltags.ForEachSqlNode.apply(ForEachSqlNode.java:79)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode$$Lambda$13/128359175.accept(Unknown Source)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:39)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:297)
at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:64)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:41)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:46)
at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:576)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Process finished with exit code -1
正在回答
哈哈哈哈 看看这个
https://blog.csdn.net/qq_43584064/article/details/115696543
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星