以'x'开头的标识符太长(SQL)

时间:2019-01-09 16:32:20

标签: java sql

我正在将日期传递到SQL查询中(这在我拥有的其他代码中有效),但由于某种原因,此处的表现不佳。我将在下面发布代码。

 Calendar limitDate = Calendar.getInstance();
        limitDate.set(Calendar.HOUR_OF_DAY, 0);
        limitDate.set(Calendar.MINUTE, 0);
        limitDate.set(Calendar.SECOND, 0);
        limitDate.set(Calendar.MILLISECOND, 0);
        //remove records 221 days old or older
        limitDate.add(Calendar.DAY_OF_YEAR, -221);
        java.sql.Date sqlDate = new java.sql.Date(limitDate.getTimeInMillis());
        int deleteCnt = 0;
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();

        StringBuilder wgpSql = new StringBuilder("select wgpapt.* ");
        wgpSql.append("from THB_View.WGPAPT wgpapt ");
        wgpSql.append("left outer join THB_View.WGP wgp on wgpapt.WGP_TAG = wgp.WGP_TAG ");
        wgpSql.append("where wgpapt.CREATE_DATE <= '" + sqlDate + "' ");
        wgpSql.append("and wgp.RECORD_KEY is null");
        List<Object[]> sqlResultSet = ExecuteSql.executeNativeSqlString(wgpSql.toString(), null);

我在控制台中遇到的错误是:以'Ljava.lang.Object; @ 4906038d,[Ljava.lang.Object; @ 366cabed,[Ljava.lang.Object; @ 651d74a9,[Ljava。 lang.Object; @ 354aea35,[Ljava.lang.O'过长。最大长度为128。

编辑:我的完整代码如下

package com.yrc.mcc.app.batch;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.yrc.mcc.core.core.MccMidusException;
import com.yrc.mcc.core.file.MList;
import com.yrc.mcc.core.program.BatchProgram;
import com.yrc.mcc.core.sql.ExecuteSql;
import com.yrc.mcc.data.file.Wgpapt;


@Component
@Scope("prototype")
public class BShp830 extends BatchProgram {

    public int deleteRecords(Map<String, List<String>> recordKeys) {
        MList<Wgpapt> delList = new MList<>();
        delList.populateFromTypeMap(Wgpapt.class, recordKeys);
        for (Wgpapt record : delList) {
            record.delete();
        }
        recordKeys.get("").clear();
        int result = 0;

        try {
            this.commit();
            print("Succesfully deleted " + delList.size() + " records");
            result = delList.size();
            // Do we want a delay here?
        } catch (MccMidusException mme) {
            if ("0080".equals(mme.getErrorCode())) {
                this.getIoHarness().pokeUow(mme.getUow());
                // Call commit to get a new transaction started.
                this.commit();
                // Reset the counter.
            } else {
                throw mme;
            }
        }
        return result;

    }

    @Override
    public void process() {
        // Find the first 5,000 records to remove.
        Calendar limitDate = Calendar.getInstance();
        limitDate.set(Calendar.HOUR_OF_DAY, 0);
        limitDate.set(Calendar.MINUTE, 0);
        limitDate.set(Calendar.SECOND, 0);
        limitDate.set(Calendar.MILLISECOND, 0);
        //remove records 221 days old or older
        limitDate.add(Calendar.DAY_OF_YEAR, -221);
        java.sql.Date sqlDate = new java.sql.Date(limitDate.getTimeInMillis());
        int deleteCnt = 0;
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();

        StringBuilder wgpSql = new StringBuilder("select wgpapt.* ");
        wgpSql.append("from THB_View.WGPAPT wgpapt ");
        wgpSql.append("left outer join THB_View.WGP wgp on wgpapt.WGP_TAG = wgp.WGP_TAG ");
        wgpSql.append("where wgpapt.CREATE_DATE <= '" + sqlDate.toString() + "' ");
        wgpSql.append("and wgp.RECORD_KEY is null");
        List<Object[]> sqlResultSet = ExecuteSql.executeNativeSqlString(wgpSql.toString(), null);

        int i = 0;
        Map<String, List<String>> recordKeys = new HashMap<>();
        recordKeys.put("", new ArrayList<String>());

        for (Object value : sqlResultSet) {
            recordKeys.get("").add(value.toString());
            i++;
            if (i == 100) {
                deleteRecords(recordKeys);
                deleteCnt += i;
                print("Running delete count is: " + deleteCnt);
                i = 0;
            }
        }

        if (i != 0) {
            // Ensure anything else gets committed.
            deleteRecords(recordKeys);
            deleteCnt += i;
        }
        print("** P R O C E D U R E  S H P 8 3 0", false);
        print("** DELETING RECORDS WITH A CREATE DATE ", false);
        print("** PRIOR TO " + limitDate.getTime().toString(), false);
        print("** TOTAL WGPAPT RECORDS DELETED = " + deleteCnt, false);
        print("*****************************************", false);
        print("** PROCEDURE SHP830 COMPLETED * ", false);
        print("** AT: " + formatter.format(date) + " *", false);
        print(" ", false);

        this.webDone();
    }
}

1 个答案:

答案 0 :(得分:0)

我解决了自己的问题。我的SQL语句说("select wgpapt.* ");,它获取整个结果而不是我尝试获取的记录键序列。这太长了,导致我的代码出错。

解决方案是将我的select语句更改为

("select wgpapt.RECORD_KEY ");