作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Java 将新节点插入到 exit-db 时遇到问题。
如果我从 eXide 运行此 Xquery,它将运行良好并插入新部门:
更新插入 < DEP_ROW >< DEPT_NO >1< DNOMBRE >A< LOC >A 到/departamentos
但是,如果我尝试从 Java 执行此操作,它会提示存在语法错误。代码是:
String queryString = "update insert <DEP_ROW><DEPT_NO>1</DEPT_NO><DNOMBRE>A</DNOMBRE><LOC>A</LOC></DEP_ROW> into /departamentos";
consulta = conn.prepareExpression(queryString);
consulta.executeQuery();
错误是:
Exception in thread "main" javax.xml.xquery.XQException:
XQJQS001 - Invalid XQuery syntax, syntax does not pass static
validation.
Root Cause:
XQueryParseException: Encountered "insert" at line 1, column 8.
Was expecting one of:
<EOF>
"%%%" ...
"=" ...
"," ...
"or" ...
"and" ...
"to" ...
"*" ...
"div" ...
"idiv" ...
"mod" ...
"union" ...
"|" ...
"intersect" ...
"except" ...
"instance" ...
"treat" ...
"castable" ...
"cast" ...
"!=" ...
"<=" ...
">" ...
">=" ...
"eq" ...
"ne" ...
"lt" ...
"le" ...
"gt" ...
"ge" ...
"is" ...
"<<" ...
">>" ...
"[" ...
"-" ...
"+" ...
"<" ...
"/" ...
"//" ...
"(" ...
at Visualizar.insertadep(Visualizar.java:58)
at Visualizar.main(Visualizar.java:23)
at Visualizar.insertadep(Visualizar.java:58)
at Visualizar.main(Visualizar.java:23)
非常感谢您的帮助。
谢谢
最佳答案
我遇到了与 Yeray 完全相同的问题,并看到了这篇文章。我现在已经找到了解决方案,所以我回来分享我的代码,我希望这可以帮助 Yeray 或其他人。
public class InsertDepartment {
public static final String DRIVER = "org.exist.xmldb.DatabaseImpl";
public final static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";
public final static String COLLECTION = "/db/first_steps";
public final static String USERNAME = "admin";
public final static String PASSWORD = "";
public static void main(String[] args) throws Exception {
String value = "";
Class cl = Class.forName(DRIVER);
Database database = (Database) cl.newInstance();
DatabaseManager.registerDatabase(database);
Collection col = DatabaseManager.getCollection(URI + COLLECTION, USERNAME, PASSWORD);
int depNumber = 42;
String depName = "Department 42";
String depAddress = "42 Galaxy Avenue, Betelgueuse 23458 OH";
String sQuery = "update insert <department><dep_number>" + depNumber
+ "</dep_number><dep_name>" + depName + "</dep_name><dep_address>"
+ depAddress + "</dep_address></department> into /departments";
EXistXQueryService service = (EXistXQueryService) col.getService("XQueryService", "1.0");
service.setProperty("indent", "yes");
service.query(sQuery);
}
请注意,为了使此代码正常工作,我最终在项目中得到了以下库列表。此代码的工作可能不需要某些内容。
exist-xqj-1.0.1.jar
j8fu-1.21.jar
log4j-1.2-api-2.11.0.jar
log4j-api-2.11.0.jar
log4j-core-2.11.0.jar
log4j-jul-2.11.0.jar
log4j-slf4j-impl-2.11.0.jar
org.apache.commons.pool.jar
org-apache-commons-logging.jar
ws-commons-util-1.0.2.jar
xmldb-api-1.7.0.jar
xmlrpc-client-3.1.3.jar
xmlrpc-common-3.1.3.jar
xqj2-0.0.1.jar
xqjapi.jar
exist.jar
exist-optional.jar
此外,我还必须将文件 log4j2.xml 添加到项目的 src 文件夹中。您可以在 this post 中找到此文件的示例。 .
关于java - 使用 Java 插入 ExistDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53323289/
我在使用 Java 将新节点插入到 exit-db 时遇到问题。 如果我从 eXide 运行此 Xquery,它将运行良好并插入新部门: 更新插入 1AA 到/departamentos 但是,如果我
我有一个关于 eXistDB 的问题:升级到 eXistDB 5.2.0 后,出现以下错误: HTTP 错误 500 javax.servlet.ServletException:javax.serv
我是一名优秀的程序员,十分优秀!