aspose file tools*
The moose likes JDBC and the fly likes Storing images to database through JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Storing images to database through JDBC" Watch "Storing images to database through JDBC" New topic
Author

Storing images to database through JDBC

Gvn Karthik
Greenhorn

Joined: Feb 07, 2011
Posts: 22
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?
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3433
    
  47

BLOB is definitely the type to go with, as I've explained in the other post of yours in this forum.

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.
Gvn Karthik
Greenhorn

Joined: Feb 07, 2011
Posts: 22
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?


Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3433
    
  47

I'm sorry, I won't be able to help. I've no experience with persistence frameworks, just plain old JDBC.

The Object Relational Mapping forum would be probably better suited for this thread. Try searching that forum for "BLOB", perhaps someone has already encountered similar problem.

Anyway, you should post the definition of the mapping you use (it is usually an XML file) and specify which persistence framework you're using, including version. Others might be able to help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing images to database through JDBC
 
Similar Threads
Need some advice on designing a scanned document archive system.
how to store object in a table
Fetching Image Data
Binary to string conversion
store image in mysql using visual jsf in netbeans 6