Heejung
Heejung

Reputation: 31

Mybatis error : The error occurred while setting parameters

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.UnsupportedOperationException
### The error may exist in kr/co/techinmotion/mybatis/mappers/dataOutputMapper.xml
### The error may involve kr.co.techinmotion.mybatis.mappers.dataOutputMapper.selectData1-Inline
### The error occurred while setting parameters
### SQL: select * from tbl_id, tbl_feed     where tbl_id.id = tbl_feed.upid     and tbl_id.token = ?
### Cause: java.lang.UnsupportedOperationException
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
at kr.co.techinmotion.daoImpl.DataDaoImplMybatis.selectData1(DataDaoImplMybatis.java:47)

I don't know why this error occurred.

This is my sql in mapper.

<select id="selectData1" parameterType="string" resultType="list">
    select * from tbl_id, tbl_feed  
    where tbl_id.id = tbl_feed.upid  
    and tbl_id.token = #{token}
</select>

and.. this is DAO.

public class DataDaoImplMybatis implements IdataDao {

    private DataDaoImplMybatis(){}

    private static DataDaoImplMybatis dao;

    public static DataDaoImplMybatis getInstance(){
        if(dao == null){
            dao = new DataDaoImplMybatis();
        }

        return dao;
    }

    SqlSessionFactory sessionFactory = SqlMapSessionFactory.getSqlSessionFactory();

    @Override
    public List<DataResult1> selectData1(String token){
        SqlSession session = sessionFactory.openSession();
        List<DataResult1> list = session.selectList("kr.co.techinmotion.mybatis.mappers.dataOutputMapper.selectData1", token);
        session.close();

        return list;
    }

}

please help me.. T_T

Upvotes: 1

Views: 54890

Answers (5)

Hailin Tan
Hailin Tan

Reputation: 1109

In my case was that added 'useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true' in jdbc.url, that solved my issue:)

jdbc.url=jdbc:mysql://127.0.0.1:3306/xxx?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true

Upvotes: 1

Aamir Iqubal
Aamir Iqubal

Reputation: 327

You have to declare the "jdbcType=VARCHAR" or "jdbcType=NUMERIC" of the variable depending upon the type of variable passed in order to pass the null value. Try using this:

<select id="selectData1" parameterType="string" resultType="map">
    select * from tbl_id, tbl_feed  
    where tbl_id.id = tbl_feed.upid  
    and tbl_id.token = #{token,jdbcType=VARCHAR}
</select>

Upvotes: 0

Wil
Wil

Reputation: 21

The "MyBatis-3-User-Guide" says: resultType: The fully qualified class name or alias for the expected type that will be returned from this statement. Note that in the case of collections, this should be the type that the collection contains, not the type of the collection itself. Use resultType OR resultMap, not both.

Upvotes: 2

mousycoder
mousycoder

Reputation: 1

1 floor is right, but I want to say resultType = "" respect a row in your database but not all, perhaps you may select count(user_id) from user, now your resultType = 'long', if you select more than two results, you may use resultType = 'map' or yourself map, resultType = 'yourselfMap'

Upvotes: 0

Ian Lim
Ian Lim

Reputation: 4274

The resultType SHOULD NOT be list, the below shows the revised type, but you have to make sure the select statement can map to DataResult1 accordingly

<select id="selectData1" parameterType="string" resultType="DataResult1">
    select * from tbl_id, tbl_feed  
    where tbl_id.id = tbl_feed.upid  
    and tbl_id.token = #{token}
</select>

alternatively, you may try this:

<select id="selectData1" parameterType="string" resultType="map">
    select * from tbl_id, tbl_feed  
    where tbl_id.id = tbl_feed.upid  
    and tbl_id.token = #{token}
</select>

and the changes to the java source code

List<Map<String,Object> list = session.selectList("kr.co.techinmotion.mybatis.mappers.dataOutputMapper.selectData1", token);

Upvotes: 0

Related Questions