Advertisement
LoonerSF

my Tema Resource

Aug 10th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package com.ipn.escom.testerRest.resources;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7.  
  8. import javax.ws.rs.GET;
  9. import javax.ws.rs.Path;
  10. import javax.ws.rs.Produces;
  11. import javax.ws.rs.core.Context;
  12. import javax.ws.rs.core.MediaType;
  13. import javax.ws.rs.core.Request;
  14. import javax.ws.rs.core.UriInfo;
  15.  
  16. import com.ipn.escom.testerRest.db.Connector;
  17. import com.ipn.escom.testerRest.modelo.Tema;
  18.  
  19. @Path("/temas")
  20. public class TemaResource {
  21.     @Context
  22.     UriInfo uriInfo;
  23.     @Context
  24.     Request request;
  25.    
  26.     private Connector conn;
  27.    
  28.     @GET
  29.     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  30.     public List<Tema> getTemas() throws SQLException{
  31.         conn=new Connector();
  32.         List<Tema> temas=new ArrayList<Tema>();
  33.         String selTemas="select * from temas;";
  34.         ResultSet rs= conn.ejecutarSelect(selTemas);
  35.         while(rs.next()){
  36.             Integer id=rs.getInt("id_tema");
  37.             String nb = rs.getString("nb_tema");
  38.             String ds = rs.getString("ds_tema");
  39.             temas.add(new Tema(id, nb, ds));
  40.         }
  41.         conn.terminarSesion();
  42.        
  43.         return temas;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement