描述:新库数据入旧库,数据为每小时更新。我从新库里查出来的数据都是不重复的,因为数据量比较大,所以每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;
}
}请教大虾如何解决(第一次发帖,如有不妥还请多多包涵)?

解决方案 »

  1.   

    最后那个。你那个最后的数据的id保存起来。这样下次查的时候从那个Id后查起,就可以了。可以保存成一个properti文件。
      

  2.   

    这类问题,先单步调试。另外把MYSQL的一般查询日志打开。
      

  3.   

    查看过日志文件了了,不是mysql的问题,我是这样解决的if (j > 0) {
    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("入库结束");
    }
    }