getBytes vs getBinaryStream vs getBlob for getting data out of a BLOB column

There are 3 different ways to get data out of a Blob column: getBytes getBinaryStream getBlob

Also, the Blob object returned by getBlob also has a getBytes and getBinaryStream on it.

Are there any particular reasons (performance, memory, database specific problems) that I should pick one over the other?

The Blob object also has a free() call that has been introduced since JDBC 4.0. Does that make a difference?

Answer:1

If you're going to be pulling a lot of data (i.e. enough data to cause memory problems), then getBinaryStream will give you most flexibility to process and discard the data as you read it in.

On the other hand, this could be quite slow, depending on your JDBC driver, since each read from the stream could entail a lot of network chatter with the database. If you call getBytes, then the driver knows to fetch the whole lot in one go, which is likely to be more efficient.

getBlob() returns a "pointer" to the data, which you can manipulate using the methods on the Blob interface. If you need to modify or otherwise get fancy with the data in-situ, then this might be best for you.

Answer:2

I was studying about bluetooth and I was trying to write the code to keep listening to the input stream while connected and i came across this following code snippet: int data = mmInStream.read(); ...

Some time ago I asked this question. All solutions are workarounds. Now this can't be. I feel that something is wrong here, but I can't tell if it is Swing's MVC model that is conceptually wrong, or ...

In onCreate() method of activity I have this code for ToolBar: toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ...

Relating to my earlier question, I want to ensure all the child objects are loaded as I have a multiple threads that may need to access the data (and thus avoid lazy loading exceptions). I understand ...