Announcement Announcement Module
Collapse
No announcement yet.
Query with like Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query with like

    Hi...

    I'm trying to make a query with a SQL "like" but simpleJdbcTemplate is not returning results... (it should return two results)

    This is my code:

    Code:
    Map<String, String> parametros = new HashMap<String, String>();
    parametros.put("razon_social", nombreRemiseria);
    SimpleJdbcTemplate simpleJdbcTemplate = getSimpleJdbcTemplate();
    List<Remiseria> remiserias = null;
    try {
    	remiserias = simpleJdbcTemplate.query(
    	"select id, razon_social, cuit, domicilio from REMISERIAS where razon_social like \"%:razon_social%\"",
    new RemiseriaMapper(), parametros);
    } catch (DataAccessException dae) {
    logger.warn("Hubo una excepción al intentar buscar una remiseria por nombre: "+dae.getMessage());
    }
    Also I've tried this:

    Code:
    Map<String, String> parametros = new HashMap<String, String>();
    	parametros.put("razon_social", "'"+nombreRemiseria+"'");
    	SimpleJdbcTemplate simpleJdbcTemplate = getSimpleJdbcTemplate();
    	List<Remiseria> remiserias = null;
    	try {
    		remiserias = simpleJdbcTemplate.query(
    			"select id, razon_social, cuit, domicilio from REMISERIAS where razon_social like '%:razon_social%'",
    	new RemiseriaMapper(), parametros);
    } catch (DataAccessException dae) {
    logger.warn("Hubo una excepción al intentar recuperar una remiseria: "+dae.getMessage());
    }
    and this:

    Code:
    Map<String, String> parametros = new HashMap<String, String>();
    	parametros.put("razon_social", nombreRemiseria);
    	SimpleJdbcTemplate simpleJdbcTemplate = getSimpleJdbcTemplate();
    	List<Remiseria> remiserias = null;
    	try {
    		remiserias = simpleJdbcTemplate.query(
    			"select id, razon_social, cuit, domicilio from REMISERIAS where razon_social like '%:razon_social%'",
    	new RemiseriaMapper(), parametros);
    	} catch (DataAccessException dae) {
    logger.warn("Hubo una excepción al intentar recuperar una remiseria: "+dae.getMessage());
    }
    No one does what it should... any help will be appreciated...
    thanks!

  • #2
    Try:

    Code:
    Map<String, String> parametros = new HashMap<String, String>();
    	parametros.put("razon_social", "%"+nombreRemiseria+"%");
    	SimpleJdbcTemplate simpleJdbcTemplate = getSimpleJdbcTemplate();
    	List<Remiseria> remiserias = null;
    	try {
    		remiserias = simpleJdbcTemplate.query(
    			"select id, razon_social, cuit, domicilio from REMISERIAS where razon_social like :razon_social",
    	new RemiseriaMapper(), parametros);
    } catch (DataAccessException dae) {
    logger.warn("Hubo una excepción al intentar recuperar una remiseria: "+dae.getMessage());
    }

    Comment


    • #3
      That's what I liked to do...
      Thanks!!!

      Comment

      Working...
      X