前提
Mybatisを使用したプロジェクトを作成してます。
マッパーインターフェイスファイルは以下のように記述しております。
List<A> selectTargetSite(@Param("pStjh") STJH pStjh, @Param("hstartdate")String hstartdate);
Aはentityファイルです。
実現したいこと
SQL文を正しく実行できるようにしたいです。
発生している問題・エラーメッセージ
以下のエラーメッセージが出ています。
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='pStjh.SITE', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 列索引が無効です。
The error may exist in UKCMDB01Mapper.xml
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: ※SQL文※
Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='pStjh.SITE', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 列索引が無効です。
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) at com.sun.proxy.$Proxy3.selectTargetSite(Unknown Source) at com.example.demo.common.UKCMDB01.UKCMDB01(UKCMDB01.java:95) at com.example.demo.Main.main(Main.java:66)
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='pStjh.SITECD', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 列索引が無効です。
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:89)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:85)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:63)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:77)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:61)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
... 7 more
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 列索引が無効です。
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:55)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)
... 16 more
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 列索引が無効です。
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:55)
at org.apache.ibatis.type.UnknownTypeHandler.setNonNullParameter(UnknownTypeHandler.java:45)
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:53)
... 17 more
Caused by: java.sql.SQLException: 列索引が無効です。
at oracle.jdbc.driver.OraclePreparedStatement.setFormOfUseInternal(OraclePreparedStatement.java:10137)
at oracle.jdbc.driver.OraclePreparedStatement.setFormOfUseInternal(OraclePreparedStatement.java:10118)
at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:4879)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setString(OraclePreparedStatementWrapper.java:257)
at org.apache.ibatis.type.StringTypeHandler.setNonNullParameter(StringTypeHandler.java:31)
at org.apache.ibatis.type.StringTypeHandler.setNonNullParameter(StringTypeHandler.java:26)
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:53)
... 19 more
該当のソースコード
<select id="selectTargetSite" resultType="A"> SELECT TBL1.SITE , TO_CHAR(TBL1.START_DATE,'YYYYMMDD'), TBL1.DEL_FLG FROM STJH TBL1, (SELECT SITE, MAX(START_DATE) BASE_START FROM STJH WHERE START_DATE <![CDATA[<=]]> TO_DATE(#{hstartdate}','YYYYMMDD') GROUP BY SITE ) TBL2 WHERE TBL1.SITE = TBL2.SITE <if test='pStjh.DELFLG == "L"'> AND TBL1.SITE = #{pStjh.SITE} </if> <if test='pStjh.DEL_FLG == "M" and pStjh.SITE == " " and pStjh.SITE == ""'> AND TBL1.SITE<![CDATA[>]]> #{pStjh.SITE} </if> <if test='pStjh.DEL_FLG == "M"'> AND TBL1.SITE like #{pStjh.SITE} || '%' </if> ORDER BY TBL1.SITE </select>試したこと
・SQL文で引数を使用しているところの記述を#{SITE, jdbcType=VARCHAR}に変更
(念のためCHAR等も試してみました)
java自体が初心者でどうしようかとても悩んでいます。
文自体がおかしい点も多々あるでしょうが何か解決方法ございましたらご教授いただけますと幸いです。
あなたの回答
tips
プレビュー