• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ByteArray converted to a String to store in database

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a ByteArray converted into a String



where baos is a ByteArrayOutputStream. I was thinking if it's ok to store it in the database(through Java code) this way especially if I'm going to use PreparedStatement... Any help would be appreicated. Thanks guys!
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most databases have a datatype specifically designed for Binary Large OBjects; this datatype is called "BLOB" and is what most people use to store image data in a database.

Most databases have internal limits on the size of character strings supported by the normal string datatypes, but many have an unlimited size string datatype, called CLOB (character large object). For your purposes, if they have CLOB, then almost certainly have BLOB, and you should be using that.

There are examples on the web for how to use these datatypes for images; try Google.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic