Announcement Announcement Module
Collapse
No announcement yet.
JdbcTemplate not working with left outer join Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Hi

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

    regards
    Grzegorz Grzybek

    Comment


    • #3
      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?

      Comment


      • #4
        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, 04:26 AM.

        Comment


        • #5
          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...

          Comment

          Working...
          X