简体   繁体   English

如何处理数据类型为float的表列中的空值

[英]How to handle null value in a table column with data type float

I have a table "hit", with a column data_value with float data type (default value: NULL): 我有一个表“ hit”,其中的列data_value具有浮点数据类型(默认值:NULL):

DROP TABLE IF EXISTS `hit`;
CREATE TABLE  `hit` (
  `hit_id` bigint(20) NOT NULL auto_increment,
  `data_value` float default NULL,
  PRIMARY KEY  (`hit_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

How should I handle this in java when I do: getDataValue()? 执行以下操作时应如何在Java中处理此问题:getDataValue()? I'd like it to return NULL if the value is null, but it returns 0.0. 我希望如果值为null,则返回NULL,但它返回0.0。 Thanks, 谢谢,

David 大卫

Use one of the uppercase Java classes instead of the primitive, eg: 使用大写Java类之一代替原始类,例如:

  • Float instead of float 浮动而不是浮动
  • Double instead of double 加倍而不是加倍
  • BigDecimal 大十进制

Primitives can't take the value null , they always default to 0 instead. 基本体不能采用null ,而是始终默认为0。 The classes will allow you to use null as well. 这些类将允许您也使用null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM