• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Reading images from Database to Sevlet

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Performed the following steps to create table to store images
create table blobs
( id varchar2(255),
blob_col blob
);
create or replace directory MY_FILES as 'c:\images';

create or replace procedure insert_img as
f_lob bfile;
b_lob blob;
begin
insert into blobs values ( 'MyGif', empty_blob() )
return blob_col into b_lob;
f_lob := bfilename( 'MY_FILES', 'duke.png' );
dbms_lob.fileopen(f_lob, dbms_lob.file_readonly);
dbms_lob.loadfromfile( b_lob, f_lob, dbms_lob.getlength(f_lob) );
dbms_lob.fileclose(f_lob);
commit;
end;
BEGIN insert_img END;

I didn�t get any errors and procedures are working successfully�..

Now next task is to read this image file in a servlet, used the following code:

PreparedStatement stmnt = c.prepareStatement("select BLOB_COL from blobs");
ResultSet rs = stmnt.executeQuery();
while(rs.next())
{
try
{
// Get as a BLOB
System.out.println("in BLOB");
Blob aBlob = rs.getBlob(1);
allBytesInBlob = aBlob.getBytes(1, (int) aBlob.length());
}
catch(Exception e){}
}


"in BLOB" is never displayed in the console ��..this means the code went wrong somewhere��.???
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the while is rs.next(). Not knowing off the top of my head. Does ResultSet have a hasNext() method to tell whether you have another record. Maybe you only have one record and the while code uses it up, so that the while is done, and doesn't execute anything in the loop.

Can you find out how many records are in the ResultSet?

Mark
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
welll........it turned out the mistake am doing is not entering 'commit' after inserting rows in the table!!! anyways i found another way to retrieve images...instead of storing the actual image in the table i will only store the path of the image as normal text and according to the query from the midlet the servlet will seek in the table and return the apporipriate url to the midlet..... its almost working except am loosing the string reference out of the catch block...which am sure will work out....soo is it a good practice to do like this???
reply
    Bookmark Topic Watch Topic
  • New Topic