gpt4 book ai didi

java - 你会在 MySQL 中映射 Java/Hibernate 中的 BigDecimal 什么类型?

转载 作者:IT老高 更新时间:2023-10-28 13:00:05 30 4
gpt4 key购买 nike

在经历了之前开发的大量代码之后,我意识到我需要移动所有基于金钱的列以不使用 float 学。在 Java 方面,这意味着使用 BigDecimal,但是当使用 Hibernate/JPA 和 MySQL 5 时,生成该列的适当 MySQL 数据类型是什么?

最佳答案

十进制和数字。

The recommended Java mapping for the DECIMAL and NUMERIC types isjava.math.BigDecimal. The java.math.BigDecimal type provides mathoperations to allow BigDecimal types to be added, subtracted,multiplied, and divided with other BigDecimal types, with integertypes, and with floating point types.

The method recommended for retrieving DECIMAL and NUMERIC values isResultSet.getBigDecimal. JDBC also allows access to these SQL typesas simple Strings or arrays of char. Thus, Java programmers can usegetString to receive a DECIMAL or NUMERIC result. However, this makesthe common case where DECIMAL or NUMERIC are used for currency values rather awkward since it means that application writers have toperform math on strings. It is also possible to retrieve these SQLtypes as any of the Java numeric types.

看看here了解更多详情。

关于java - 你会在 MySQL 中映射 Java/Hibernate 中的 BigDecimal 什么类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550337/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com