mybatis + DB2数据库常见报错:jdbc type 0 not yet supported

来源:互联网 发布:iphone刷机后数据恢复 编辑:程序博客网 时间:2024/06/06 21:03


mybatis + DB2数据库常见报错:jdbc type 0 not yet supported。

        最近做项目,我也遇到了这个问题,并且多次遇到了,有时候改改这里,动动那里,问题也解决了,
但是不搞清楚这个问题的根本原因,还是不放心。我的情况是这样的:进行一个数据库查询操作,会向后台
传递一个参数,SQL大致是这样的:
SELECT
    PRODUCT_NAME, PRODUCT_COLOR
FROM
    PRODUCT
WHERE
    PRODUCT_NAME = #PRODUCT_NAME#

在前台,我们需要把PRODUCT_NAME的值传递给数据库,但是也可能会出现不传值的情况。

思考一个问题:下面的2个查询语句,执行时,会报错吗?为什么?
SELECT * FROM TABLENAME WHERE NAME = '';
SELECT * FROM TABLENAME WHERE NAME = NULL;

互联网上,关于这个问题,最多的文章,下面这个帖子,内容大致如下:

Hey all,y/nnnnnnnnnyy
I would like to share you guys this problem im getting constantly by using
Ibatis via jdbc to do queries on DB2...

Let's say we have written a simple query like this

SELECT
    PCT_SCO_MAX,
FROM
    FLES_PERC_SCO
WHERE
    COD_COMPANY = #codCompany# AND
    COD_SELLER  = #codSeller#

the JDBC drivers via Ibatis framework CANNOT map a EMPTY STRING value into
"codSeller". infact it maps "null"  as you can see in the log:

DEBUG [java.sql.PreparedStatement]--<{pstm-105524} Parameters: [112, null]>

but this way makes your query NOT fetch any results...

So i've rounded the problem witha /dynamic TAG but this solution is not
stylish ;

<isNotEmpty prepend="AND" property="codSeller">
    COD_SELLER = #codTipoUnita#
</isNotEmpty>
<isEmpty prepend="AND" property="codSeller">
    COD_SELLER = ''
</isEmpty>

someone got a better idea???

        通过上面的方式,是可以解决这个报错问题的。笔者在实际项目中进行过测试。这里整理一下,mark一下,
下次再遇到这种报错,就能快速定位问题。


0 0