Foros del Web » Programación para mayores de 30 ;) » Java »

Obtener campos de tabla a partir de un método.

Estas en el tema de Obtener campos de tabla a partir de un método. en el foro de Java en Foros del Web. Buenas, verán tengo un problema, quiero obtener todos los campos de una tabla a partir de una sentencia que obtiene los id. El método es ...
  #1 (permalink)  
Antiguo 15/12/2015, 22:36
LDN
 
Fecha de Ingreso: diciembre-2015
Mensajes: 22
Antigüedad: 8 años, 5 meses
Puntos: 0
Mensaje Obtener campos de tabla a partir de un método.

Buenas, verán tengo un problema, quiero obtener todos los campos de una tabla a partir de una sentencia que obtiene los id. El método es el siguiente:

public String idHistorial(String id) {
String json = "";
try {
Query query =em.createNativeQuery("select id_historial_activo, activo FROM beacons_agencias.historial_activos where oficina = \""+id+"\"", HistorialActivos.class);
List<HistorialActivos> listHistorial = (List<HistorialActivos>)query.getResultList();
for(HistorialActivos perfil: listHistorial){
json += perfil.getIdHistorialActivo()+",";
}
} catch (Exception e) {
FCom.printDebug(e.getMessage());
json = "[{\"id\":\"\",\"text\":\"NO EXISTEN OPCIONES\"}]";
}
return json;
//To change body of generated methods, choose Tools | Templates.
}


Lo intento así
String filter="where ";
String nombre = usuario.getIdOficina().getNombreOficina();
ids = HistorialEJBLocal.oficina(nombre);
for(int i=0;i<1;i++) {
filter += " ID_HISTORIAL_ACTIVO = "+ids;
i++;
}

Y en otro método:
public String select(int rows, int page, String sort, String order, String search) {
String json;
int inicio = ((page - 1)* rows);
try {
Query queryTotal = em.createNativeQuery("SELECT COUNT(1) FROM HISTORIAL_ACTIVOS " + search);
int count = Integer.parseInt(queryTotal.getSingleResult().toSt ring());
String query = "select * from historial_activos " + search + " order by " + sort + " " +order;
String queryPaginado = query + " LIMIT " + inicio + "," + rows;
Query queryRegistros = em.createNativeQuery(queryPaginado, HistorialActivos.class);
List<HistorialActivos> listPerfil = (List<HistorialActivos>)queryRegistros.getResultLi st();
json = "{\"data\":[";
for(HistorialActivos perfil: listPerfil){
json += perfil.toString()+",";
}
if(count > 0)
json = json.substring(0, json.length() - 1);
json += "],\"total\":"+count+"}";
}catch(NumberFormatException e){
FCom.printDebug(e.getMessage());
json = "{\"data\":[],\"total\":0}";
}
return json;

search contiene: where ID_HISTORIAL_ACTIVO = 11,12,13,15,16,17,18,

Alguna idea de recorrer eso.

Gracias.

Etiquetas: campos, string, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:10.