JDBC ResultSet对象类型映射是否没有Byte或Short?为什么只选择整数? [英] JDBC ResultSet object types mapping has no Byte or Short? Why Integer only?

查看:105
本文介绍了JDBC ResultSet对象类型映射是否没有Byte或Short?为什么只选择整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天.谁能解释为什么JDBC不为某些类型实现对象映射.例如,Postgres JDBC没有字节和短映射.我可以获取原始字节和短字节,但是在对象格式中,我只能获取Integer.

Good day. Can anyone explain why JDBC doesn't implement object mapping for some types. For example, Postgres JDBC has no Byte and Short mapping. I can get primitive byte and short, but in object format I can get only Integer.

这是来自此处

case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
    return getInt(columnIndex);

字节和短对象类型有什么问题?我如何使用TINYINT,SMALLINT等.

What's wrong wtih Byte and Short object types? How can I work with TINYINT, SMALLINT and so on.

实现getByte和getShort类似于

What's problem to implement getByte and getShort similar to getInt

推荐答案

答案在

The answer is in the JDBC™ 4.1 Specification JSR 221 on page 187

注意 – JDBC 1.0规范定义了Java对象映射,用于 将SMALLINT和TINYINT JDBC类型设置为Integer. Java语言 JDBC 1.0时不包括Byte和Short数据类型 规格已完成. SMALLINT和TINYINT到的映射 保持整数以保持向后兼容性.

Note – The JDBC 1.0 specification defined the Java object mapping for the SMALLINT and TINYINT JDBC types to be Integer. The Java language did not include the Byte and Short data types when the JDBC 1.0 specification was finalized. The mapping of SMALLINT and TINYINT to Integer is maintained to preserve backwards compatibility.

这篇关于JDBC ResultSet对象类型映射是否没有Byte或Short?为什么只选择整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆