Solucionar el OAD para filtrar búsquedas
Hola amigo, espero me puedas ayudar. Necesito crear la select para que en función de si un campo del formulario de mi jsp esta rellenado(C_CATEGORIA_FAQ_ID), me haga una select filtrada o no.. Mi idea es que lo haga para más campos, pero de momento vamos a intentar que solo lo haga con uno.
Esto es lo que tengo en el OAD:
public ArrayList consultaKUROCategoriasFaq(KUROCategoriasFaqOT categoriasFaqOT, int inicio, int cuantos)
//public ArrayList consultaKUROCategoriasFaq(long cPrueba, String dPrueba, String aDescripcion, Date fInicio, int inicio, int cuantos)
throws Exception {
PreparedStatement st = null;
ResultSet rs = null;
Connection con=JCYLGestionTransacciones.getConnection();
ArrayList listado = null;
try {
StringBuffer sbWhere = new StringBuffer(100);
String selectFrom = "SELECT C_CATEGORIA_FAQ_ID, C_CATEGORIA_FAQ_PADRE, D_CATEGORIA_FAQ, " +
"D_DESCRIPCION, B_BORRADO, U_CREACION, TO_CHAR(F_CREACION,'DD/MM/RRRR') F_CREACION," +
" U_MODIFICACION, TO_CHAR(F_MODIFICACION,'DD/MM/RRRR') F_MODIFICACION " +
"FROM KURO_CATEGORIAS_FAQ " ;
String orderBy="order by C_CATEGORIA_FAQ_ID";
/*
String where = "";
boolean primerFiltro = true;
if (!cCategoriaFaqID.equals("")){
if (primerFiltro){ where+= " WHERE ";primerFiltro=false;}
else{where+= " AND ";}
where += "C_CATEGORIA_FAQ_ID=" + categoriasFaqOT.getCCategoriaFaqID();
}
if (!dDescripcion.equals("")){
if (primerFiltro){ where+= " WHERE ";primerFiltro=false;}
else{where+= " AND ";}
where+= "D_DESCRIPCION='" + categoriasFaqOT.getdDescripcion()+ "'";
}
*/
String sqlStatement = new StringBuffer(selectFrom).append(orderBy).toString();
KUROConfigApp.logger.info("Sentencia SQL:"+sqlStatement);
st = con.prepareStatement(sqlStatement,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
int index=1;
KUROCategoriasFaqOT datos = new KUROCategoriasFaqOT();
/*if (isCPrueba)
st.setLong(index++,cPrueba);*/
rs = st.executeQuery();
if (inicio >1)
rs.absolute(inicio-1);
listado = new ArrayList();
int i = 0;
while (rs.next()) {
datos = new KUROCategoriasFaqOT();
datos.setCCategoriaFaqID(rs.getLong("C_CATEGORIA_FAQ_ID"));
datos.setCCategoriaFaqPadre(rs.getLong("C_CATEGORIA_FAQ_PADRE"));
datos.setDCategoriaFaq(rs.getString("D_CATEGORIA_FAQ"));
datos.setDDescripcion(rs.getString("D_DESCRIPCION"));
datos.setBBorrado(rs.getString("B_BORRADO"));
datos.setUCreacion(rs.getString("U_CREACION"));
datos.setFCreacion(rs.getString("F_CREACION"));
datos.setUModificacion(rs.getString("U_MODIFICACION"));
datos.setFModificacion(rs.getString("F_MODIFICACION"));
listado.add(datos);
if (++i == cuantos)
break;
} // while
} catch (Exception ex) { KUROConfigApp.logger.error(ex.getMessage());
throw ex;
} finally {
if (rs != null)
rs.close();
if (st != null)
st.close();
JCYLGestionTransacciones.close(con.getAutoCommit());
} //...
Esto es lo que tengo en el OAD:
public ArrayList consultaKUROCategoriasFaq(KUROCategoriasFaqOT categoriasFaqOT, int inicio, int cuantos)
//public ArrayList consultaKUROCategoriasFaq(long cPrueba, String dPrueba, String aDescripcion, Date fInicio, int inicio, int cuantos)
throws Exception {
PreparedStatement st = null;
ResultSet rs = null;
Connection con=JCYLGestionTransacciones.getConnection();
ArrayList listado = null;
try {
StringBuffer sbWhere = new StringBuffer(100);
String selectFrom = "SELECT C_CATEGORIA_FAQ_ID, C_CATEGORIA_FAQ_PADRE, D_CATEGORIA_FAQ, " +
"D_DESCRIPCION, B_BORRADO, U_CREACION, TO_CHAR(F_CREACION,'DD/MM/RRRR') F_CREACION," +
" U_MODIFICACION, TO_CHAR(F_MODIFICACION,'DD/MM/RRRR') F_MODIFICACION " +
"FROM KURO_CATEGORIAS_FAQ " ;
String orderBy="order by C_CATEGORIA_FAQ_ID";
/*
String where = "";
boolean primerFiltro = true;
if (!cCategoriaFaqID.equals("")){
if (primerFiltro){ where+= " WHERE ";primerFiltro=false;}
else{where+= " AND ";}
where += "C_CATEGORIA_FAQ_ID=" + categoriasFaqOT.getCCategoriaFaqID();
}
if (!dDescripcion.equals("")){
if (primerFiltro){ where+= " WHERE ";primerFiltro=false;}
else{where+= " AND ";}
where+= "D_DESCRIPCION='" + categoriasFaqOT.getdDescripcion()+ "'";
}
*/
String sqlStatement = new StringBuffer(selectFrom).append(orderBy).toString();
KUROConfigApp.logger.info("Sentencia SQL:"+sqlStatement);
st = con.prepareStatement(sqlStatement,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
int index=1;
KUROCategoriasFaqOT datos = new KUROCategoriasFaqOT();
/*if (isCPrueba)
st.setLong(index++,cPrueba);*/
rs = st.executeQuery();
if (inicio >1)
rs.absolute(inicio-1);
listado = new ArrayList();
int i = 0;
while (rs.next()) {
datos = new KUROCategoriasFaqOT();
datos.setCCategoriaFaqID(rs.getLong("C_CATEGORIA_FAQ_ID"));
datos.setCCategoriaFaqPadre(rs.getLong("C_CATEGORIA_FAQ_PADRE"));
datos.setDCategoriaFaq(rs.getString("D_CATEGORIA_FAQ"));
datos.setDDescripcion(rs.getString("D_DESCRIPCION"));
datos.setBBorrado(rs.getString("B_BORRADO"));
datos.setUCreacion(rs.getString("U_CREACION"));
datos.setFCreacion(rs.getString("F_CREACION"));
datos.setUModificacion(rs.getString("U_MODIFICACION"));
datos.setFModificacion(rs.getString("F_MODIFICACION"));
listado.add(datos);
if (++i == cuantos)
break;
} // while
} catch (Exception ex) { KUROConfigApp.logger.error(ex.getMessage());
throw ex;
} finally {
if (rs != null)
rs.close();
if (st != null)
st.close();
JCYLGestionTransacciones.close(con.getAutoCommit());
} //...
1 respuesta
Respuesta de fbluisg