java 我们如何使用 BigInt?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2100437/
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
how we use BigInt?
提问by Johanna
this is my code but it givas an error would you please help me(in mySQL I have a table that has VARCHAR name ,VARCHAR address and VARCHAR telephone and TINYINT age and BIGINT charge)
这是我的代码,但它给出了一个错误,请帮助我(在 mySQL 中,我有一个表,其中包含 VARCHAR 名称、VARCHAR 地址和 VARCHAR 电话以及 TINYINT 年龄和 BIGINT 费用)
I want to insert a name and address and telephone and age with calling this method .but it will give an error for line insertARow("Adam Smit","21 First Avenue, Fairlyland, 87654","123456789",35);
ERROR:create an InsertARow method(String,String,String,Int);
我想在调用此方法时插入姓名和地址以及电话和年龄。但它会给出错误行insertARow("Adam Smit","21 First Avenue, Fairlyland, 87654","123456789",35);
ERROR:create an InsertARow method(String,String,String,Int);
the class:
班上:
insertARow("Adam Smit","21 First Avenue, Fairlyland, 87654","123456789",35);
}
private static void insertARow(String name,String address,String telephone,BigInt age) {
}
回答by Joachim Sauer
A BIGINTin MySQLis a 64 bit integer type, so you can simply handle it as a long(and/or Long) value in Java, as long as you are using the SIGNEDvariant.
BIGINTMySQL中的A是 64 位整数类型,因此您可以简单地将其作为Java 中的long(和/或Long)值处理,只要您使用的是SIGNED变体。
If you want to support an UNSIGNED BIGINT, then you will have to handle the values as java.math.BigIntegerin Java.
如果要支持UNSIGNED BIGINT,则必须像java.math.BigInteger在 Java 中一样处理这些值。
Since you don't show any code that actually interfaces with the Database (JDBC) I can't tell you what you're doing wrong.
由于您没有显示任何实际与数据库 (JDBC) 接口的代码,因此我无法告诉您您做错了什么。
回答by Adamski
Your code is attempting to use BigInt as a Java type, which will not compile. As Joachim mentions you need to use a longor Longin Java.
您的代码正试图将 BigInt 用作 Java 类型,该类型将无法编译。正如 Joachim 提到的,您需要在 Java 中使用 along或Long。

