2012-11-11 3 views
0
select 
       ID,NAME,SEX,RESIDENCE,EMAIL,MOBILE,PASSWORD,MOOD,BIRTHDAY,AVATAR,TYPE,MONEY 
      from 
       user 
      where 
       ID in 
        (select USER2 as id from friend where USER1=#userId# and STATUS= 1 union select user1 as id from friend where user2 = #userId# ) 



select 
       ID,NAME,SEX,RESIDENCE,EMAIL,MOBILE,PASSWORD,MOOD,BIRTHDAY,AVATAR,TYPE,MONEY 
      from 
       user 
      where 
       ID in 
        (select USER2 as id from friend where USER1=#userId# and STATUS= 1) 

Если я использую второй SQL это нормально, если я использую первый, он работает error.I думаю параметр нормально, как два SQL имеют одинаковые параметрыIbatis ошибка в SQL

org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; 
--- The error occurred in com/bit/hapin/dao/activity/activity.xml. 
--- The error occurred while applying a parameter map. 
--- Check the getInviteFriendForActivity-InlineParameterMap. 
--- Check the parameter mapping for the 'userId' property. 
--- Cause: java.lang.ArrayIndexOutOfBoundsException: 1; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: 
--- The error occurred in com/bit/hapin/dao/activity/activity.xml. 
--- The error occurred while applying a parameter map. 
--- Check the getInviteFriendForActivity-InlineParameterMap. 
--- Check the parameter mapping for the 'userId' property. 
--- Cause: java.lang.ArrayIndexOutOfBoundsException: 1 
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:121) 
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:322) 
    at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212) 
    at org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:249) 
    at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:296) 
    at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:290) 
    at com.bit.hapin.dao.activity.ActivityDAOImpl.getInviteFriendForActivity(ActivityDAOImpl.java:51) 

Так что мне делать?

+0

может понравиться 'параметр map' и его классы Java? – CycDemo

+0

'Карта map = new HashMap (); \t \t \t map.put ("userId", this.getUserId()); \t \t \t map.put ("activityId", this.getActivityId()); 'Я не думаю, что что-то не так с картой параметров, поскольку я использую тот же параметр, что все нормально – dustdn

ответ

0

В первом запросе нет проблем. Но,

В первом запросе:

select USER2 as id from friend ..... select user1 as id from friend .... 

Что означает friend таблицы имеет USER2 и user1 столбцов. Если это так, убедитесь, что таблицы таблиц (USER2, user1) находятся в таблице friend. Хотя я не знаю вашего требования к программе, второго запроса (в вашем сообщении) достаточно из-за того, что вы пытаетесь сделать union с таблицей single/same.

Вы также можете ссылаться: Union on the same table

+0

Если user1 = userId, я хочу user2 , И если user2 = userId, я хочу user1. Я знаю, что есть другие решения, но я все еще хочу знать, почему это происходит неправильно – dustdn

Смежные вопросы