用 Java 将 MySQL 的 Tiny int 转换为 Integer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24649103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 13:44:26  来源:igfitidea点击:

Tiny int of MySQL to Integer in Java

javamysqlhibernate

提问by Mayank_Thapliyal

I have an tiny intcolumn in MySQL. I want to convert it into int type of java.

tiny int在 MySQL 中有一个列。我想把它转换成java的int类型。

So if I mention the column in my hibernate entity as

因此,如果我将休眠实体中的列提到为

@Column(name="Columname")
private int something;

Will it cause an error as tiny int needs boolean type or will it get cast into int?

它会导致错误,因为 tiny int 需要布尔类型还是会被转换为 int?

This code will be changed in production Db hence I cannot check it to see if it breaks.

此代码将在生产数据库中更改,因此我无法检查它是否中断。

采纳答案by PVR

JDBC driver maps databse type to java. So in case of mysql TINYINTwill be converted to java.lang.Booleanor java.lang.Integer.

JDBC 驱动程序将数据库类型映射到 java。所以在 mysql 的情况下TINYINT会转换为java.lang.Booleanor java.lang.Integer

Refer this link which explains : Java, JDBC and MySQL Types

请参阅此链接,其中解释了: Java、JDBC 和 MySQL 类型

回答by Vishal_Kotecha

Go for the datatype Byte. it worked for me!

选择数据类型Byte。它对我有用!