开发者

How to return an ArrayList from a database query?

I am querying a 开发者_如何学Godatabase 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?


  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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜