gpt4 book ai didi

java - 当我尝试插入数据时,eXist-db 出错

转载 作者:行者123 更新时间:2023-12-01 18:23:07 24 4
gpt4 key购买 nike

我正在做一个学校项目,该项目需要 .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

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

最佳答案

.csv 中存在错误,其中 2 行包含符号 <在数据内部,无法添加这两行。

关于java - 当我尝试插入数据时,eXist-db 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60271713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com