Results 1 to 5 of 5

Thread: JdbcTemplate not working with left outer join

  1. #1
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    93

    Question JdbcTemplate not working with left outer join

    hi,

    I have a left outer join query which gives the result in the oracle-sql-developer.
    But when i try to get the results for this query using jdbctemplate it gives me a wrong ans.

    My query is
    Code:
    String sqlQuery = 
    select *  from table1 t1 left outer join table2 t2  on t1.code = t2.it_code  where  t1.group_code = ?  and  t2.emp_code = ? and t1.is_active  =? and t2.is_active  = ?  order by t1.created_on
    This query returns 2 rows in oracle sqldeveloper but with jdbctemplate it returns 0.
    This is how i am using the jdbctemplate.
    Code:
    jdbcTemplate.query(sqlQuery, new Object[] { 
    			groupCode, emp_code, IS_ACTIVE_FLAG,IS_ACTIVE_FLAG }, new int [] {Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR},
    				new RowCallbackHandler()
    				{
    					@Override
    					public void processRow(ResultSet rs) throws SQLException
    					{
    						map.put("count", rs.getInt(1));
    					}
    				});
    
    		log.info("count is " + map.get("count"));
    Normal queries are working fine.But left outer join query gives wrong results.

    Please help.Where am i going wrong.
    Thanks in advance.
    Regards,
    Annuk

  2. #2
    Join Date
    Oct 2008
    Location
    Poland, Wrocław
    Posts
    432

    Default

    Hi

    Don't use "*" in SELECTS - explicitely specify columns (giving aliases if necessary) and use column names in processRow.

    regards
    Grzegorz Grzybek

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Also how do you know it returns 0 rows? You put something in a map and later on print it.. So not sure where you get the count from?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    93

    Thumbs up

    Hi Grzegorz,

    Thanks for your reply.
    When i used the column names it worked.

    Can you please tell why "*" doesnt work while using a join in jdbctemplate.
    Regards,
    Annuk
    Last edited by annuk; Dec 1st, 2011 at 04:26 AM.

  5. #5
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    93

    Default

    Hi Marten,

    Before putting in the map,i had a log which prints the rs.getInt(1).
    It is giving me 0.

    Thanks for your reply...

Tags for this Thread

Posting Permissions

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