views:

84

answers:

1

I am querying a database for a web service using the Jersey JAX-RS. I can return a single row as XML or JSON, but I can't figure out how to return multiple records.

Do I use an ArrayList? If so how? Does anyone have an example of how to do this?

Thanks

+2  A: 
  1. Create a RowHolder class that defines all the fields from the table
  2. Annotate the RowHolder with @XmlType
  3. Use a List<RowHolder> with @XmlElement on it.

How to get the date in the List<RowHolder> -

List<RowHolder> list = new LinkedList<RowHolder>();

while (rs.next())  {
    RowHolder holder = new RowHolder();
    holder.setName(rs.get("name"));
    holder.setSurname(rs.get("surname"));
    holder.setEmail(rs.get("email"));
    // etc. for all the relevant fields
    list.add(holder);
}
Bozho
Yes, but I need to use JAXB so Jersey can output it as XML or JSON.
Bill
@Bill see my update
Bozho
Thanks I'll try it tomorrow
Bill
Can you post an example of this?
John
of which? of trasnferring the `ResultSet` to a `RowHolder`? That's straightofward - just call `holder.setName(rs.get(1))`; etc.
Bozho