Querying the database

Hi again! :smiley:

I came acrossed a problem. I am to write a java program to retrieve records from the Tamino database.

I read the documentation on “Say hello!”, Tamino API for java. The doc helped alot for establishing the connection and obtaining an accessor.

So far my program can be compiled, the problem I came acrossed was the query part:

//Instantiate an empty TXMLObject instance using the DOM object model
TXMLObject xmlObject = TXMLObject.newInstance(TDOMObjectModel.getInstance());

//Establish the Tamino connection
TConnection connection = TConnectionFactory.getInstance().newConnection(DATABASE_URI);

//Obtain a TXMLObjectAccessor with a DOM object model
TXMLObjectAccessor xmlObjectAccessor = connection.newXMLObjectAccessor(TAccessLocation.newInstance(“TCM”),TDOMObjectModel.getInstance());

//Prepare to read the instance
TQuery query = TQuery.newInstance(xmlObject.getDoctype() + “[@ino:id=” + xmlObject.getId() + “]”);

//Invoke the query operation
TResponse response = xmlObjectAccessor.query(query);

The error was, com.softwareag.tamino.db.API.accessor.TQueryException
Access Failure:
ReturnValue:8320
Code:INOXIE8320
MessageText:Error parsing the XQL query
MessageLine:Unexpected token [ found
at com.softwareag.tamino.db.API.accessor.TAccessFailureVerifier.verifyQueryResponse(TAccessFailureVerifier.java:67)
at com.softwareag.tamino.db.API.accessor.TXMLObjectAccessorImpl.query(TXMLObjectAccessorImpl.java:234)
at GetInput.(GetInput.java:35)
at GetInput.main(GetInput.java:60)

What do you think is wrong?

-KAren-
:rolleyes:

Hi Karen.
I think the problem is that because you just created an empty TXMLObject, it doesn’t have a doctype (or ino:id) yet. So getDocType returns null and the query is invalid without a doctype before the opening “[”.

You could substitute strings with known values for the document type and ino:id, and the query should work:

String myDocType = “doctype”;
String myInoId = “123”;

TQuery query = TQuery.newInstance(myDocType + “[@ino:id=” + myInoId + “]”);

The example provided in the API package (com.softwareag.tamino.db.API.examples.greeting.XMLGreeting.java) inserts a record first, then does a query to get it back.

Heya Bill!

Thanks for replying. I managed to get it done!!!

:smiley: