I want to store images in Oracle database through a JDBC program. In my program, I'm reading an image file as a stream of bytes and storing it in a byte array.
What should be the datatype of the image column in the corresponding table in the database. I used BLOB and CLOB but they are accepting images of sizes as small as 3 kB. What should be the datatype used for storing images in database for large images?
I've described Oracle-specific way to insert BLOBs into table for example in this thread here on Javaranch.
Depending on your needs, you might prefer database independent way to do it. In that case I suggest you search for JDBC BLOB tutorial on the web. There are countless examples. Read a few of them, try to understand what's going on and play with them a bit. If you still have problems, post your code (using a code tag) and a thorough explanation of what does not work (eg. the exception you're encountering and a stack trace).
I guess, just guess that you're trying to insert the data as a text. That may hit Oracle's size limit for VARCHAR2 SQL variables which is 4000 bytes; it might be less in characters due to the fact that some characters may be multi-byte ones.
posted 9 years ago
In the code below I'm reading an image file. The function readImageOldWay(file) reads the file into a byte array as shown by the class ImageService below the class ImageMain.
The above code is being used in a JPA project and not JDBC. But the requirement is the same - inserting a bigger size image instead of an image of hardly 10kB. When I insert a bigger image say of size above 150kB, I get the following exception. What should I be doing to get rid of this exception? How can I insert bigger images?