Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem regarding Image save/retrieve

 
kshitij raval
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
I encountered this exception only when I try to save a big image. The jpg image was only as big as 5436 bytes.
The reason for this exception is explained at http://www.wamoz.com/JDBC_and_Oracle_LOB.asp, that
LONG data types (LONGVARBINARY, LONGVARCHAR etc) are the original kind of blob. Because the LONG data is fetched with each row, this makes each fetched row potentially very large. It uses up the fetch buffer very quickly and makes the database server much less efficient because far fewer rows will fit in memory.
The site has also given the solution in the form of downloads, but there is dependency on two of its packages:
(1) com.Trysoft.bpe and (2) com.wamoz.db. And discussed that the solution to this is saving a big image in small chunks.
I am interested in solving this problem using pure Java, i.e., either JDK1.2 or JDK1.3 classes ONLY. Can anyone help me out?
 
kshitij raval
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not yet found the solution to saving big images in Oracle using Java can anyone help ???
 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kshitij,
I encountered similar problem when I tried to read large images from Oracle Blob. During testing I found out that I cound not read any image greater than 32K. Here is how I got around. I read the blob until I finish reading in 32K chunks - storing the data in temp place holder. The code below:
++++++++++++++++++++++++++++++++++++++++++++++++++++
try
{
int byteCount = 0;
int newLength = 0;
int readLength = 0;
while ( newLength < blobLen)
{
if ((newLength+32500) <= blobLen)
{
data = blob.getBytes (newLength+1, 32500);
newLength = newLength + 32500;
readLength = 32500;
}
else
{
readLength = (int) (blobLen - newLength);
data = blob.getBytes (newLength+1, readLength);
newLength = newLength + readLength;
}

for (byteCount = 0; byteCount < readLength; byteCount++)
{
try
{
TIFFFile.write (data[byteCount]);
}
catch (Exception e)
{
System.err.println ("Error writing data for TIFF @ address " + newLength);
return;
}
}
}
}
catch (Exception e)
{
System.out.println ("Exception: Unable to write output file: "+e.getMessage());
return;
}
+++++++++++++++++++++++++++++++++++++++++++++

This may help.
Good luck.
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic