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��.???