Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java sql中的ibatis错误_Java_Mysql_Sql_Ibatis - Fatal编程技术网

Java sql中的ibatis错误

Java sql中的ibatis错误,java,mysql,sql,ibatis,Java,Mysql,Sql,Ibatis,如果我使用第二个sql,它是可以的,如果我使用第一个sql,它运行错误。我认为参数是可以的,因为两个sql具有相同的参数 select ID,NAME,SEX,RESIDENCE,EMAIL,MOBILE,PASSWORD,MOOD,BIRTHDAY,AVATAR,TYPE,MONEY from user where ID in

如果我使用第二个sql,它是可以的,如果我使用第一个sql,它运行错误。我认为参数是可以的,因为两个sql具有相同的参数

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)

那我该怎么办呢?

第一次查询没有问题。但是,

在第一个查询中:

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)
这意味着
friend
表有
USER2
user1
列。如果是,请确保
friend
表中的表列(USER2,user1)。虽然我不知道您的程序要求,但是第二个查询(在您的帖子中)已经足够了,因为您正在尝试使用
单个/相同的
表来
联合


您还可以参考:

能否请
参数映射
及其java类?
map map=new HashMap();map.put(“userId”,this.getUserId());put(“activityId”,this.getActivityId())我不认为参数映射有什么问题,因为我使用了相同的参数一切正常如果user1=userId,我想要user2。如果user2=userId,我想要user1。我知道还有其他解决办法,但我还是想知道为什么会出错
select USER2 as id from friend ..... select user1 as id from friend ....