views:

90

answers:

4

I am building a webservice using jax-rs and querying a DB2 z/OS database with SQLJ and getting the result set as an arraylist. I would like to return this list as XML, but not sure how to do it.

Does anyone have an example of returning a result set as XML and is using an Arraylist the best way to do this?

Should I use JAXB? if so how?

A: 

you did not say which database you are using, on SQL Server you would use FOR XML

here is an example

USE AdventureWorks
GO
SELECT Cust.CustomerID, 
       OrderHeader.CustomerID,
       OrderHeader.SalesOrderID, 
       OrderHeader.Status,
       Cust.CustomerType
FROM Sales.Customer Cust 
INNER JOIN Sales.SalesOrderHeader OrderHeader
ON Cust.CustomerID = OrderHeader.CustomerID
FOR XML AUTO
SQLMenace
A: 

Perhaps XMLEncoder.writeObject(arrayList)

But this doesn't have to do with the database. Its DB > ArrayList > xml

Bozho
A: 

Easiest way is probably using jdom.

steve l
A: 

XStream is a simple library to serialize objects to XML and back again.

Have a look at their tutorial, you can extrapolate from it pretty quickly how an arraylist would be serialized.

P. Deters