How to update XML using XPath and Java

Use setNodeValue. First, get a NodeList, for example: myNodeList = (NodeList) xpath.compile(“//MyXPath/text()”) .evaluate(myXmlDoc, XPathConstants.NODESET); Then set the value of e.g. the first node: myNodeList.item(0).setNodeValue(“Hi mom!”); More examples e.g. here. As mentioned in two other answers here, as well as in your previous question: technically, XPath is not a way to “update” an XML document, but … Read more

What does it mean when Statement.executeUpdate() returns -1?

As the statement executed is not actually DML (eg UPDATE, INSERT or EXECUTE), but a piece of T-SQL which contains DML, I suspect it is not treated as an update-query. Section 13.1.2.3 of the JDBC 4.1 specification states something (rather hard to interpret btw): When the method execute returns true, the method getResultSet is called … Read more

How to set and check cookies wih JAX-RS?

You can do the following: To store a new cookie: @GET @Path(“/login”) @Produces(MediaType.TEXT_PLAIN) public Response login() { NewCookie cookie = new NewCookie(“name”, “123”); return Response.ok(“OK”).cookie(cookie).build(); } To retrieve the cookie (javax.ws.rs.core.Cookie): @GET @Path(“/foo”) @Produces(MediaType.TEXT_PLAIN) public Response foo(@CookieParam(“name”) Cookie cookie) { if (cookie == null) { return Response.serverError().entity(“ERROR”).build(); } else { return Response.ok(cookie.getValue()).build(); } } However, … Read more

Eclipse 2021-06: ClassFormatError accessible: module java.base does not “opens java.lang” to unnamed module

Thanks, @howlger it was Lombok plug-in when using JDK 16. That tweet gave me the reasons: https://github.com/projectlombok/lombok/issues/2810 A workaround : Use Java 15 to start Eclipse or add –illegal-access=warn and –add-opens=java.base/java.lang=ALL-UNNAMED to your eclipse.ini or install a pre-built version (1.18.21) In my situation I had to change eclipse.ini VM path: -vm C:\bin\jdk-15.0.2\bin