I would like to insert some unsigned int value using a prepared statement.
setInt() slaps me with a DataTruncation if the second parameter is above 2,147,483,647 (Max Signed Int) although my underlying table can chew up to 4,294,967,295 (Max Unsigned Int)
Is there such a thing as setUnsignedInt()? Should I use setLong() although the table is setup as (INT(10) UNSIGNED)?
Thanks
Yes, you should use setLong(). You'll note that the javadocs tell you:
Sets the designated parameter to the given Java long value. The driver converts this to an SQL BIGINT value when it sends it to the database.
So be aware that it would allow you to set a value larger than 2^32-1 which would then be rejected by the DB (hopefully; I suppose it could wrap).
To do this you use the next smallest data type that will hold the current max (unsigned) value. For Integer that would be Long. You can then discard anything above the max (unsigned) value for Integer.
This post will shed some light
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With