store into mysql Meduimtext and largtext

when I want store variable in Mysql using JDBC what type shoud I get for mediumtext and larg text?
can i get String or must get Byte[]?

Answer

Java array indexes are integers, so you can have at most Integer.MAX_VALUE bytes in array which is 2^31-1 or one byte short of 2Gb.

String is the same deal as it’s backed by character array (though the actual memory footprint of a maximum length String would be twice the above since Java stores them in Unicode).

MySQL’s maximum size for MEDIUMTEXT is 16Mb, LONGTEXT is 4Gb. So the former would fit into both String and byte array while the latter won’t fit in either. In practice, however, you’ll hit many other problems before you get to that point 🙂 so you can use String for either medium or long text.

Leave a Reply

Your email address will not be published. Required fields are marked *