Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes When to use setBytes() and setBinaryStream() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "When to use setBytes() and setBinaryStream()" Watch "When to use setBytes() and setBinaryStream()" New topic
Author

When to use setBytes() and setBinaryStream()

Amol Desai
Ranch Hand

Joined: Jan 29, 2003
Posts: 82
Hi,
I am using oracle thin driver to insert a image (blob type) into database.
Which method of PreparedStatement interface should I use to insert data,
setBytes() or SetBinaryStream().
My understanding is BinaryStream also sends data in form of bytes.
Then what is the difference between these two method ?
Please let me know.
Thanks,
-Amol
[ September 01, 2003: Message edited by: Amol Desai ]
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
If you can use the setBinaryStream, do so. It will use memory buffering to read the stream and send a block at a time to the server. This is especially important if the binary data is extremely large. However, if you are holding a reference to the entire block of bytes in memory already, then use setBytes. Get it?
Ex - if you are reading the image data from the network, or from a file, than use setBinaryStream. If you have a byte array because you already read the stream, use setBytes. However, I'd strongly suggest finding a way to "read on demand" if the files are large.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When to use setBytes() and setBinaryStream()
 
Similar Threads
Getting error while saving image as blob in oracle
dealing with images/pictures
reading a very complex file and inserting in database
creating and inserting Blob
Upload attachment using Java