For my university-project I installed an h2database locally on my computer. I have a little data in it and now I am trying to export parts of this data via the included xml-functions that h2 offers.
However I do not really get how this works. I am working with SQL Workbench/J to test and after it works I implement it in my java program.
For example I have the XMLNODE-function which works like this (taken from the h2 manual):
XMLNODE(elementString [, attributesString [, contentString [,indentBoolean]]])
Create an XML node element. An empty or null attribute string means no attributes are set. An empty or null content string means the node is empty. The content is indented by default if it contains a newline. This method returns a string. Example:
CALL XMLNODE('a', XMLATTR('href', '``https://h2database.com``'), 'H2')
So when I call CALL XMLNODE('a', XMLATTR('href', 'https://h2database.com'), 'H2')
I get:
<a href="https://h2database.com">H2</a>
all fine...
But when I only use the XMLNODE without the XMLATTR like this: CALL XMLNODE('a', 'H2');
I get the following output:
<aH2/>
So I dont know what I am doing wrong cause I do not even come to the point where I can put some data in it cause when I only use the NODE it does not seem like good xml^^
Btw: When I am trying to get the resultset via my java program it just tells me that there is no data. here is the code:
s = conn.createStatement();
String query = "CALL XMLNODE('test1', XMLATTR('test2', 'test3'), 'test4');";
rs = s.executeQuery(query);
String val = rs.getString(1);
System.out.println(val);
The explanation in the manual says that it is returning a String
I fixed it! Here is a good example of how to use it: https://github.com/h2database/h2database/blob/master/h2/src/test/org/h2/samples/newsfeed.sql