Hello!
I have been trying to update my tamino db, unfortunately I haven’t achive any success!
Here is my sample code:
-----------------------------------------------
import java.util.;
import org.w3c.dom.;
import com.softwareag.tamino.API.dom.*;
public class update {
public static final void main(String arg) throws Exception {
TaminoClient tc = new TaminoClient(“http://localhost/tamino/mydb/col”);
tc.setPageSize(0);
tc.startSession();
try {
TaminoResult tr = tc.query(“doc[id_client=‘12345’]”);
Document dc = tr.getDocument();
Element el = dc.getDocumentElement();
NodeList nl = el.getElementsByTagName(“surname”).item(0).getChildNodes();
String OldNodeValue = nl.item(0).getNodeValue();
String NewNodeValue = “KOWALSKI”;
nl.item(0).setNodeValue(NewNodeValue);
tc.process(el);
tc.commit(true);
tc.endSession();
} catch (com.softwareag.tamino.API.dom.TaminoError Error) {
System.err.println("Tamino Error Code: " + Error.responseCode + “\n” +
"Tamino Error Text: " + Error.errorText);
}
}
}
-----------------------------------------------
I tried to modify value using tagname “surname” to “KOWALSKI” string value.
I used process method which should update my db.
In documentation I found:
-----------------------------------------------
public final TaminoResult process(org.w3c.dom.Element element)
throws java.io.IOException, TaminoError
The process method will attempt to store the element using HTTP/1.1 POST and the _process verb. If the attribute ino:id is set to a numeric value in the domain of ino IDs, the element will overwrite the element with this ID if it already exists, or it will be inserted with this ino:id. If no ID is present, a unique ID will be assigned. A Tamino Result object is returned. The document type and the ino:id can be extracted from the Result object.
Parameters:
a - DOM element containing XML to process.
Returns:
the Tamino Result Object containing the DOM Object
Throws:
the - Tamino error object
the - IOException object
-----------------------------------------------
Please help me!
Any help will be appreciated!
Thanks a lot in advance!
best regards,
Dariusz Baumann
Hi Dariusz,
The process() method takes an element of the document you want to update, but what you are passing is an element containing the whole response document from the query. So as an example if the query doc[id_client=‘12345’] returns just one document, then you can get the element of the document using something like:-
Document dc = tr.getDocument();
Element el = (Element)tr.getResult().getChildNodes().item(0);
…
tc.process (el);
Hope this helps,
Stuart
Element el = (Element)tr.getResult().getChildNodes().item(0);
…
tc.process (el);
------------------------
Thanks a lot Stuart Fyffe-Collins! Now it works.
I just wonder if getResult() and getElement() methods are returning the same value?
-------------------------------------------------
Element el = (Element)tr.getResult().getChildNodes().item(0);
-------------------------------------------------
Element el = (Element)tr.getElement().getChildNodes().item(0);
-------------------------------------------------
best regards,
Dariusz Baumann
I think getElement() and getResult() actually do return the same value!