需要创建dbf文件,为此我使用dans-dbf-lib-1.0.0-beta-10.jar。尝试插入数字字段时:

final Map<String, Value> map = new HashMap<String, Value>();
map.put("NM", new StringValue("RST014"));
map.put("SOURCE", new StringValue("NKK"));
map.put("ST", new StringValue("WT"));
map.put("JE_BANK", new StringValue("MP"));
map.put("JE_LANG", new StringValue("RU"));
map.put("LIMIT", new NumberValue(1000));
Record record = new Record(map);
dbfTable.addRecord(record);

在下面的代码之后,我有一个异常
dbflib.ValueTooLargeException: Number does not fit in the field 'LIMIT': 1000.

我怎样才能解决这个问题?

最佳答案

通过以下代码简单地解决了该问题:

private static final String[] COLUMN_NAMES = new String[] {
        "NM", "SOURCE", "ST", "DATE_S", "DATE_E",
        "ID", "LDAP", "JE_BANK", "JE_LANG", "INFCL",
        "LIMIT", "REFCON", "CLSIGN", "COUNT", "COMM",
        "ATTR5", "ATTR20", "ATTR21", "ATTR26", "ATTR27", "ATTR28",
        "F", "I", "O", "Tel", "Product", "Kod_text", "Product_new", "Email"
    };

private static final Type[] COLUMN_TYPES = new Type[] {
    Type.CHAR, Type.CHAR, Type.CHAR, Type.CHAR, Type.CHAR,
    Type.NUMBER, Type.CHAR, Type.CHAR, Type.CHAR, Type.CHAR,
    Type.NUMBER, Type.CHAR, Type.CHAR, Type.CHAR, Type.CHAR,
    Type.CHAR, Type.CHAR, Type.NUMBER, Type.CHAR, Type.CHAR, Type.CHAR,
    Type.CHAR, Type.CHAR, Type.CHAR, Type.CHAR, Type.CHAR, Type.NUMBER, Type.CHAR, Type.CHAR
};

private static final int[] COLUMN_PRECISION = new int[] {
        6, 3, 2, 10, 10,
        10, 1, 2, 2, 18,
        10, 75, 3, 1, 1,
        10, 1, 1, 4, 1, 17,
        254,254,254,12,254,20,254,254
    };

    for (int i = 0; i < COLUMN_NAMES.length; i++)
    {
        if (COLUMN_TYPES[i].equals(Type.CHAR))
        {
            dbfFields.add(new Field(COLUMN_NAMES[i], Type.CHARACTER, COLUMN_PRECISION[i] ));
        }
        else
        {
            Field f = new Field(COLUMN_NAMES[i], Type.NUMBER, COLUMN_PRECISION[i],0);
            dbfFields.add(f);
        }
    }

关于java - DANS DBF号码类型的用法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30596085/

10-12 13:55