We described in the previous page how to convert a complete response document into a string. In this page we will focus on retrieving parts of the response documents and converting these to other formats.
The response document is composed of parts, or activity reports, which correspond to the activities in the activities. Each activity report contains the status and, if applicable, the result data.
There are basically two ways of formatting the output of an sqlQueryStatement activity: You can retrieve the data as a string (which is encoded as a XML document conforming to the WebRowSet schema) or as a JDBC ResultSet.
SQLQuery query = new SQLQuery("select * from littleblackbook where id='3475'"); WebRowSet rowset = new WebRowSet( query ); ActivityRequest request = new ActivityRequest(); request.add( query ); request.add( rowset ); service.perform( request );
ActivityOutput output = rowset.getOutput();
String result = output.getData();
ResultSet rs = rowset.getResultSet();This allows for further processing of the results using JDBC. For example, print out the result as a table, convert it to HTML, or feed it back into another database. We will see how this is done in later pages. By default, the ResultSet object will be of type ResultSet.TYPE_FORWARD_ONLY. If you would like more flexible access to the results, for example for use in an interactive application, this can be achieved by using the setResultSetType(int) method on the WebRowSet object before calling getResultSet(). Warning: setting the result set type to ResultSet.TYPE_SCROLL_INSENSITIVE causes the entire result set to be held in memory, so should be used with caution when dealing with very large result sets.
See OGSA-DAI/examples/src/uk/org/ogsadai/examples/clienttoolkit/ProcessingSQLQueryResults.java for an example solution.
Also see a later page on Pulling Data from a Data Service back to the Client and OGSA-DAI/examples/src/uk/org/ogsadai/examples/clienttoolkit/ProcessingSQLQueryLargeResults.java for an example solution.
In this section you will learn how to retrieve output from an XPath query (xPathStatement) activity.
XPathStatement query = new XPathStatement("/entry[@id<10]"); service.perform( query );
ActivityOutput output = query.getOutput(); String data = output.getData();
ResourceSet results = query.getResourceSet(); ResourceIterator iter = results.getIterator(); while(iter.hasMoreResources()) { Resource resource = iter.nextResource(); String resourceID = resource.getId(); String contents = resource.getContent()); }
Node node = ((ResourceImpl)resource).getContentAsDOM();
See OGSA-DAI/examples/src/uk/org/ogsadai/examples/clienttoolkit/ProcessingXPathQueryResults.java for an example solution.
Back: Performing Queries | Up: Using the Client Toolkit | Next: Updates and Bulk Load |
? International Business Machines Corporation, 2002-2006 | ? The University of Edinburgh, 2002-2006 |