简体   繁体   English

什么MySQL数据类型将存储此Java BigInteger?

[英]What MySQL datatype would store this Java BigInteger?

I'm using Java 6, Hibernate 4.1.0.Final, and Spring 3.1.1.RELEASE. 我正在使用Java 6,Hibernate 4.1.0.Final和Spring 3.1.1.RELEASE。 I have a String (maximum of 32 characters) that I wish to convert to a number and then back again to a String. 我有一个字符串(最多32个字符),我希望转换为一个数字,然后再返回一个字符串。 I want to know what MySQL (v 5.5) data type I should use to store the number (which I think is a BigInteger) and I would also like to know if there's a better way to do the conversion. 我想知道我应该使用什么MySQL(v 5.5)数据类型来存储数字(我认为是BigInteger),我还想知道是否有更好的方法来进行转换。 Right now, I'm doing 现在,我正在做

// Convert to integer
final BigInteger bigInt = new BigInteger(myString.getBytes());

// Convert back to a string
final String oldString = new String(bigInt.toByteArray());

The Hibernate mapping on the field in question is 有问题的字段上的Hibernate映射是

@Column(name = "ORDER_ID")
private BigInteger orderId;

Thanks for your help, - 谢谢你的帮助, -

Look at the NUMERIC datatype. 查看NUMERIC数据类型。 I've used that to store very large decimal numbers up to 39 digits long. 我用它来存储长达39位的非常大的十进制数。

The database field has a type of "NUMERIC(39)". 数据库字段的类型为“NUMERIC(39)”。

The hibernate mapping used was: 使用的hibernate映射是:

<property name="foo" type="big_integer" column="ORDER_ID" length="39"/>

To convert a string to a BigInteger from a hex string, use: 要从十六进制字符串将字符串转换为BigInteger,请使用:

BigInteger bigInt = new BigInteger(myString, 16);

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

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