Jdbi: 未更新 row.wasNull 值

创建于 2018-10-15  ·  5评论  ·  资料来源: jdbi/jdbi

嘿,我抓住了黑幕。 BeanMapper 中的 Bean 具有 NULL 而不是存在 byte[] 值。

MySQL数据库表:

b_column varchar(10), /* value = NULL */
c_column longblob, /* value = some value */

Java 对象:

String b_column; // NULL - it's okay
byte[] c_column; // NULL - why?

正如我调试的BuiltInMapperFactory

private static <T> ColumnMapper<T> referenceMapper(ColumnGetter<T> getter) {
    return (r, i, ctx) -> {
        T value = getter.get(r, i); // value = byte[..] - not null, it's okay
        return r.wasNull() ? null : value; // r.wasNull() = true - why true?
    };
}

如果我设置 b_column 值,它工作正常。

有人可以解释一下这个案例吗?
版本:组织。 jdbi:jdbi3-核心:3.5.1

所有5条评论

r 是一个 ResultSet,AFAIK 来自您的 jdbc 数据库库......所以如果它行为不端,我认为问题出在于此。 乍一看,jdbi 中的这段代码对我来说看起来不错,尽管使用 wasNull 而不是== null在我看来有点奇怪。 也许要处理像 Null Objects 这样的常规 null 检查会误导您的事情。

referenceMapper用于包装原语,如Integer.class 。 JDBC ResultSet只提供了一个getInt(column)方法,它返回一个原始的int 。 如果该列为空,则返回0 。 因此,您_必须_ 在知道该列是否实际上为空之后调用wasNull()

实用知识,谢谢

@Romqa您使用的是哪个 JDBC 驱动程序?

@qualidafial ,是的,问题出在 mysql-connector 中,谢谢 ;)

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

electrum picture electrum  ·  3评论

kkrgwbj picture kkrgwbj  ·  4评论

jarlah picture jarlah  ·  3评论

nonameplum picture nonameplum  ·  5评论

goxr3plus picture goxr3plus  ·  4评论