eXist-db尝试插入数据时出错

问题描述 投票:0回答:1

我正在做一个学校项目,该项目需要使用.csv的[7584行,并将其保存在带有eXist-db的.xml文件中。这是我要插入的代码:

private static Collection collection = ExistConnection.getCollection();
private static XPathQueryService service;

static {
    try {
        service = (XPathQueryService) collection.getService("XPathQueryService", "1.0");
    } catch (XMLDBException e) {
        e.printStackTrace();
    }
}
public static void insert() {
    App.getCrimes().forEach(crime -> {
        try {
            String insert = "update insert" +
                    "<crime>" +
                    "<date>" + crime.getDate() + "</date>" +
                    "<address>" + crime.getAddress() + "</address>" +
                    "<district>" + crime.getDistrict() + "</district>" +
                    "<beat>" + crime.getBeat() + "</beat>" +
                    "<grid>" + crime.getGrid() + "</grid>" +
                    "<description>" + crime.getDescription() + "</description>" +
                    "<ncicCode>" + crime.getNcicCode() + "</ncicCode>" +
                    "<location>" +
                    "<latitude>" + crime.getLocation().getLatitude() + "</latitude>" +
                    "<longitude>" + crime.getLocation().getLongitude() + "</longitude>" +
                    "</location>" +
                    "</crime>" +
                    "into /crimes";
            service.query(insert);
        } catch (XMLDBException e) {
            System.out.println(e.getMessage());
        }
    });
}

现在是用于计算犯罪数量的代码:

public static void countAll() {
    try {
        ResourceSet resourceSet = service.query("let $n := count(/crimes/crime) return $n");
        ResourceIterator i = resourceSet.getIterator();
        while (i.hasMoreResources()) {
            Resource r = i.nextResource();
            System.out.println((String) r.getContent());
        }
        ExistConnection.closeCollection();
    } catch (XMLDBException e) {
        e.printStackTrace();
    }
}

当我运行该应用程序时,我得到了下一个错误以及计算犯罪数量的结果:

Failed to invoke method queryPT in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.XPathException: err:XPST0003 unexpected token: $ (while expecting closing tag for element constructor: null) [at line 1, column 171]
Failed to invoke method queryPT in class org.exist.xmlrpc.RpcConnection: org.exist.xquery.XPathException: err:XPST0003 unexpected token: $ (while expecting closing tag for element constructor: null) [at line 1, column 177]
7582

我不知道为什么只能插入7582 of 7584行的原因。我尝试删除行7583和7584,以防万一由于某些原因这些行是错误的,但是错误仍然存​​在并且计数结果是7580。

java exist-db
1个回答
0
投票

。csv中发生错误,数据中两行带有符号<,并且无法添加这两行。

© www.soinside.com 2019 - 2024. All rights reserved.