在添加到数据库之前,数据应该是checked.There,三列的项应该是unique.So --I创建一个HashMapper(HashMap Map)来恢复数据库中已经存在的数据。
HashMap<String, Object> eauMap = new HashMap<String, Object>();因此,数据库中有一个select操作,我使三个不同的键映射相同的对象。
List<Object> existObjectList = Service.getAll();
HashMap<String, Object> Map = new HashMap<String, Object>();
for (Object existdata : existEauList) {
Map.put(existdata.getip1(), existdata);
Map.put(existdata.getip2(), existdata);
Map.put(existdata.getip3(), existdata);
}然后,通过函数Map.get(key1)、Map.get(key2)、Map.get(key3).If进行循环检查,以检查每一行的添加数据是否为空,我将数据放入列表,并将其放入映射中。
for loop:
Object data = (Object) Map.get(ip1);//ip1 is from the cell value
if (data == null) {
data=(Object)Map.get(ip2);
if(data==null){
data=(Object)Map.get(ip3);
if(data==null){
…………………………
Map.put(ip1,newdata);
Map.put(ip2,newdata);
Map.put(ip3,newdata);
}
}
}然后我将列表提交到数据库中。当只有300行数据时,它可以工作。现在我加10000,服务器故障。我怎么做才能提高效率。需要指出哪个行是repeat.and,项目是由springmvc+spring+mybaits设置的
发布于 2016-08-23 08:51:56
如果需要向任何rdbms添加数千条记录,则应该使用rdbms提供的特性导入数据。
在MySQL中,导入大量数据的特性称为加载数据填充。
在目标表中,在需要唯一的字段上创建唯一索引或主键。在load data infile语句中,指定ignore子句,以便当它遇到重复条目时,导入不会停止:
load data infile 'filename' ignore into table yourtable ...更新
如果您需要识别重复的记录,那么
load data infile语句将所有数据导入临时表。inner join的简单inner join将为您提供目标表中已经存在的记录。insert ... select ... from temp_table left join target table on ... where target_table.identifier_column is null命令,只将临时表中那些不存在于标签表中的记录插入目标表中。在where条件下,如果3列的组合唯一标识记录,则可能必须指定多个列。https://stackoverflow.com/questions/39096296
复制相似问题