My Question is: How can I inset a BigInteger variable as BIGINT in MySQL DB?? It seems to me that the preparedstatement object in Java does not have a method supports this type?
-
See this answer for a workaround: stackoverflow.com/questions/4374930/store-biginteger-into-mysqlDNA– DNA2012-07-08 19:52:52 +00:00Commented Jul 8, 2012 at 19:52
-
You can use a decimal/numeric value depending on your db limits: stackoverflow.com/questions/3052772/…Martin– Martin2012-10-24 16:31:37 +00:00Commented Oct 24, 2012 at 16:31
Add a comment
|
1 Answer
According to this documentation, BIGINT is just a 64-bit integer in MySQL - so use setLong. That should be fine for signed BIGINT types in MySQL. Unfortunately Java doesn't have an "unsigned long" type, so if you have an unsigned BIGINT in your database that could be trickier - you could try still using setLong, and see whether it just overflows in the "natural" way.
3 Comments
Jon Skeet
@JuryA: "Java gives an error" is pretty vague. Please edit your question to show how you're trying to use it, what the database schema looks like, and what the error is.
Jury A
I don't remember the error syntax exactly. What I did is:
preparedStmt.setLong (myIndex, myBigIntNo); . The error meaning is that Java could not insert the value because of conflict in the data types (my number is defined in Java as BigInteger and the field in the DB as BIGINT). Currently, I solved the problem by converting the number from BigInt to Byte[] and store it as Blob in MySQL DB. Will post the solution soon once I make sure it works fine. I'm still testing it.Jon Skeet
@JuryA: Well I suggest that rather than going from memory, you write a short but complete program to demonstrate the problem, edit it into the question, and include the error message too.