How exactly was the object stored in the database anyway? As a blob? Probably you want to use getBlob() rather than getObject(), and then use the getBytes() or getBinaryStream() of the Blob class to extract the binary data from the object. Or if you're not sure how the data is stored in the DB, use
to learn what kind of object you're really dealing with.
If you have access to the code that puts the image data into the database,
you should probably post some of that to clarify what's going on.
By the way, you've found one of my pet peeves:
Why on earth does anyone write code like this?
Sure,
probably no IOException will occur, and there won't be a problem. But if anything does go wrong, you're basically telling the machine to ignore the problem and not tell you. This is Wrong. At the very least, put ioe.printStackTrace() in the catch, so that you get some indication if there's a problem.