Results 1 to 4 of 4

Thread: JdbcTemplate.queryForObject strange behaviour

  1. #1
    Join Date
    Oct 2004
    Location
    Paris (France)
    Posts
    26

    Default JdbcTemplate.queryForObject strange behaviour

    When I use the JdbcTemplate.queryForObject like the fragment below, it works fine

    StringBuffer sqlQuery = new StringBuffer("SELECT a.CodeUser");
    sqlQuery.append(" FROM Utilisateur a, Autorisation b, Groupe c, Application d ");
    sqlQuery.append(" WHERE a.CodeUser = b.CodeUser AND ");
    sqlQuery.append(" b.CodeGroupe = c.CodeGroupe AND ");
    sqlQuery.append(" d.CodeAppli=b.CodeAppli AND ");
    sqlQuery.append(" a.Login=").append(FormatterUtil.prepareString(logi n));
    sqlQuery.append(" AND a.MotDePasse=").append(FormatterUtil.prepareString (password));
    sqlQuery.append(" AND b.CodeAppli=").append(codeApplication);

    try
    {
    codeUser = (String) getJdbcTemplate().queryForObject(sqlQuery.toString(),java.lang.String.class);

    }
    catch (Exception e)
    {
    String errorMessage = "les paramétres suivants login/password:" + login + "/" + password
    + "ne sont pas habilités à l'application " + codeApplication;
    log.error(errorMessage);
    throw new AuthenticationException(e.getMessage()) ;
    }

    To improve performance, I replace the code tu use queryForObject by passing args like below:


    String codeUser = null;
    StringBuffer sqlQuery = new StringBuffer("SELECT a.CodeUser");
    sqlQuery.append(" FROM Utilisateur a, Autorisation b, Groupe c, Application d ");
    sqlQuery.append(" WHERE a.CodeUser = b.CodeUser AND ");
    sqlQuery.append(" b.CodeGroupe = c.CodeGroupe AND ");
    sqlQuery.append(" d.CodeAppli=b.CodeAppli AND ");
    sqlQuery.append(" a.Login=?");
    sqlQuery.append(" AND a.MotDePasse=?");
    sqlQuery.append(" AND b.CodeAppli=?");

    Object[] params = new Object[3];
    params[0]=FormatterUtil.prepareString(login);
    params[1]=FormatterUtil.prepareString(password);
    params[2]=new Integer(codeApplication);


    try
    {
    codeUser = (String) getJdbcTemplate().queryForObject(sqlQuery.toString (),params,java.lang.String.class);
    }
    catch (Exception e)
    {
    String errorMessage = "les paramétres suivants login/password:" + login + "/" + password
    + "ne sont pas habilités à l'application " + codeApplication;
    log.error(errorMessage);
    throw new AuthenticationException(e.getMessage()) ;
    }

    when I run this code, I get the exption below

    org.springframework.dao.IncorrectResultSizeDataAcc essException: Expected single row but found none

    I've inspected the code and it seems correct to me. Can someone tells
    resolving this problem.
    How could I manage to make spring generate the query after arguments replacements.

    thanks in advance.

  2. #2
    Join Date
    Oct 2004
    Location
    Paris (France)
    Posts
    26

    Default problem solved

    Excuse me guys,
    I've solved my problem.

  3. #3
    Join Date
    Mar 2007
    Posts
    10

    Default I got the same problem

    Could you tell me how do u solved the problem?

    thanks in advance

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I would quess your query simply didn't return any results. Either the query is wrong or it just doesn't match any data.

Similar Threads

  1. Strange setup bean behaviour with validation
    By Christian in forum Web Flow
    Replies: 4
    Last Post: Jun 20th, 2005, 05:27 PM
  2. Replies: 1
    Last Post: May 4th, 2005, 05:06 AM
  3. Replies: 0
    Last Post: Jan 3rd, 2005, 03:31 AM
  4. Desktop application, strange behaviour
    By innovate in forum Container
    Replies: 2
    Last Post: Sep 24th, 2004, 04:32 AM
  5. Replies: 5
    Last Post: Sep 8th, 2004, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •