mybatis,查询传入参数为Map,无效的列类型,空指针异常

报错信息:
ERROR - Exception occurred during processing request: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型
; uncategorized SQLException for SQL []; SQL state [null]; error code [17004]; 无效的列类型; nested exception is java.sql.SQLException: 无效的列类型

查询xml:
<select id="login" resultType="com.exam.entity.Student" parameterType="java.util.HashMap">
<![CDATA[
select * from ${schema}.student where stu_id = #{stu_id} and sys_pwd = #{sys_pwd}
]]>
</select>

我debug查看了map传入前的值,两个参数都不是空的,但是传入之后就报错,这两个字段在数据库里都是varchar类型的,我传入的是string

想知道为什么会变成空的

<select id="login" resultType="com.exam.entity.Student" parameterType="java.util.Map">
<![CDATA[
select * from ${schema}.student where stu_id = ${stu_id} and sys_pwd = ${sys_pwd}
]]>
</select>追问

为什么不能用#{stu_id},这两种取法有什么不同

追答

#{stu_id}这么调用,在xml里必须有声明,如

然后这么用 stu_id = #{stuId,jdbcType=INTEGER}
${stu_id} 这个用的就随意些,只要你map传进来的key和stu_id一样就行了
还有${schema}.student这样用不报错吗?

追问

${schema}.student,schema我定义在properties中,作为模式名的配置。

我数据库里面有个人的登录名叫 “admin”的, 然后,在页面登录,提示用户名密码错误,我看了后台日志,确实没取到数据
但是,我在pl/sql中运行select语句,和上面的差不多,能把数据取出来,后面,我把 admin 登录名改为 admin1,页面上就可以登录了

oracle

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网