描述:新库数据入旧库,数据为每小时更新。我从新库里查出来的数据都是不重复的,因为数据量比较大,所以每100条数据入一次库,问题就出现在最后插入的数据上,因为最后的数据可能不满100条,所以插入的应该也是相应的条数的,但是执行的时候程序好像每次都要补满100条数据才入库public void storeDb(){ CopyOnWriteArrayList<String> SQLS = null;
String[] execSqls = null; SQLS = SqlContainer;
SqlContainer = new CopyOnWriteArrayList<String>(); int count = 100;
if (SQLS.size() > 0) { int totalSize = SQLS.size();
execSqls = new String[count]; int j = 0;
int finishCount = 0;
for (int i = 0; i < SQLS.size(); i++) {
execSqls[j] = SQLS.get(i);
j++;
if (j >= count) {
long startTime = System.currentTimeMillis();
try {
oldCentarJdbcTemolate.batchUpdate(execSqls);
} catch (Exception e) {
logger.error("SQL exec error:" + e.getMessage());
}
long endTime = System.currentTimeMillis();
finishCount += j;
logger.info("exec SQL complete cost :"
+ (endTime - startTime) + "ms,Size : ["
+ finishCount + "/" + totalSize + "]");
j = 0;
} }
if (j > 0) {
long startTime = System.currentTimeMillis();
try {
oldCentarJdbcTemolate.batchUpdate(execSqls);
} catch (Exception e) {
logger.error("SQL exec error:" + e.getMessage());
}
long endTime = System.currentTimeMillis();
finishCount += j;
logger.info("last exec SQL complete cost :"
+ (endTime - startTime) + "ms,Size : [" + finishCount
+ "/" + totalSize + "]");
j = 0;
}
}请教大虾如何解决(第一次发帖,如有不妥还请多多包涵)?
String[] execSqls = null; SQLS = SqlContainer;
SqlContainer = new CopyOnWriteArrayList<String>(); int count = 100;
if (SQLS.size() > 0) { int totalSize = SQLS.size();
execSqls = new String[count]; int j = 0;
int finishCount = 0;
for (int i = 0; i < SQLS.size(); i++) {
execSqls[j] = SQLS.get(i);
j++;
if (j >= count) {
long startTime = System.currentTimeMillis();
try {
oldCentarJdbcTemolate.batchUpdate(execSqls);
} catch (Exception e) {
logger.error("SQL exec error:" + e.getMessage());
}
long endTime = System.currentTimeMillis();
finishCount += j;
logger.info("exec SQL complete cost :"
+ (endTime - startTime) + "ms,Size : ["
+ finishCount + "/" + totalSize + "]");
j = 0;
} }
if (j > 0) {
long startTime = System.currentTimeMillis();
try {
oldCentarJdbcTemolate.batchUpdate(execSqls);
} catch (Exception e) {
logger.error("SQL exec error:" + e.getMessage());
}
long endTime = System.currentTimeMillis();
finishCount += j;
logger.info("last exec SQL complete cost :"
+ (endTime - startTime) + "ms,Size : [" + finishCount
+ "/" + totalSize + "]");
j = 0;
}
}请教大虾如何解决(第一次发帖,如有不妥还请多多包涵)?
解决方案 »
- 服务器被攻击 病毒代码求解
- 要了亲命了!!!
- 求证 MySQL REGEXP 不走索引
- user表中,root用户的 host字段,localhost与127.0.0.1有区别吗?
- 使用query()循环插入出现MySQL server has gone away错误
- linux mysql表只能查询,不能更新和插入
- 在sql语句中含有汉字,为什么查不出结果,怎么解决?在线等,谢谢了
- 怎样能够看到MySQL服务器上正在执行的语句?
- mysql中,一个库可以最多大概可以承受多少张表?
- mysql error:Access denied for user root@localhost using password yes
- 求...MySql更新多条记录的语句....
- 带输出变量的存储过程调用问题
long startTime = System.currentTimeMillis();
try {
String[] a =new String[j];
for (int i = 0; i < a.length; i++) {
a[i]=execSqls[i];
}
oldCentarJdbcTemolate.batchUpdate(a);
} catch (Exception e) {
logger.error("SQL exec error:" + e.getMessage());
}
long endTime = System.currentTimeMillis();
finishCount += j;
logger.info("last exec SQL complete cost :"
+ (endTime - startTime) + "ms,Size : [" + finishCount
+ "/" + totalSize + "]");
j = 0;
logger.info("入库结束");
}
}