0

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?

2

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@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.
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.
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.