This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Storing images to database through JDBC

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
This tiny ad will self destruct in five seconds.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic