how to save image in oracle blob field?
Hello All,
I m using vb.net2002-03.
Can you tell me the code how to store the image in the oracle blob field?i tried but not succeed..so storing path temporarily..i want to store image it self in to database and also want to reirieve from the blob field...
I think i've to read that image in to byte array by giving path and then store the image...
and i am using oledb for that and not oracle client and i think to store this i've to add system.oracle client.dll from the add reference of project menu.
so if possible please privide me code snippet in vb.net or provide me any link that contains the similar article.....i'll be thankful to you...
Thanks & Regards,
Nil
"Problem is just the distance between the expectation and the reality"
here
http://www.codeproject.com/useritems/Blobfield.asp
create table image_blob_table (id number primary key,
width integer,
height integer,
contentLength integer,
mimeType varchar2(20),
image_blob BLOB);
or
|
create table graphics_table (
bfile_id number,
bfile_desc varchar2(30),
bfile_loc bfile,
bfile_type varchar2(4))
TABLESPACE appl_data
storage (initial 1m next 1m pctincrease 0)
/
SQL> INSERT INTO graphics_table
2 VALUES(4,'April Book of Days Woodcut',bfilename('GIF_FILES','APRIL.JPG'),'JPEG');
1 row created.
SQL> INSERT INTO graphics_table
2 VALUES(8,'August Book of Days Woodcut',bfilename('GIF_FILES','AUGUST.JPG'),'JPEG');
1 row created.
SQL> INSERT INTO graphics_table
2 VALUES(13,'Benzene Molecule',bfilename('GIF_FILES','BENZNE.GIF'),'GIF');
1 row created.
.
.
.
SQL> INSERT INTO graphics_table
2 VALUES(30,'',bfilename('GIF_FILES','SHAPIROS.GIF'),'GIF');
1 row created.
SQL> INSERT INTO graphics_table
2 VALUES(31,'',bfilename('GIF_FILES','SODF5.GIF'),'GIF');
1 row created.
SQL> INSERT INTO graphics_table
2 VALUES(32,'',bfilename('GIF_FILES','WAVRA-CL.GIF'),'GIF');
1 row created.
SQL> commit;
Commit complete.
CREATE OR REPLACE PROCEDURE get_bfiles(
bfile_dir in VARCHAR2,
bfile_lis in VARCHAR2,
bfile_int_dir VARCHAR2)
AS
cur INTEGER;
bfile_int VARCHAR2(100);
sql_com VARCHAR2(2000);
file_proc INTEGER;
file_hand utl_file.file_type;
file_buff VARCHAR2(1022);
file_type VARCHAR2(4);
BEGIN
bfile_int:=UPPER(bfile_int_dir);
file_hand:=utl_file.fopen(bfile_dir,bfile_lis,'R');
LOOP
BEGIN
utl_file.get_line(file_hand,file_buff);
cur:=dbms_sql.open_cursor;
file_type:=SUBSTR(file_buff,INSTR(file_buff,'.')+1,3);
file_type:=UPPER(file_type);
IF file_type='GIF'
THEN
file_type:='GIF';
ELSIF file_type='JPG'
THEN file_type:='JPEG';
END IF;
sql_com:= 'INSERT INTO graphics_table '||CHR(10)||
'VALUES (graphics_table_seq.NEXTVAL,'||CHR(39)||CHR(39)||
', bfilename('||
CHR(39)||bfile_int||CHR(39)||','
||CHR(39)||file_buff||CHR(39)||
') ,'||CHR(39)||file_type||CHR(39)||')';
dbms_output.put_line(sql_com);
dbms_sql.parse(cur,sql_com,dbms_sql.v7);
file_proc:=dbms_sql.execute(cur);
dbms_sql.close_cursor(cur);
EXCEPTION
WHEN no_data_found THEN
EXIT;
END;
END LOOP;
utl_file.fclose(file_hand);
END;
/
CREATE OR REPLACE PROCEDURE load_lob AS
id NUMBER;
image1 BLOB;
locator BFILE;
bfile_len NUMBER;
bf_desc VARCHAR2(30);
bf_name VARCHAR2(30);
bf_dir VARCHAR2(30);
bf_typ VARCHAR2(4);
ctr integer;
CURSOR get_id IS
SELECT bfile_id,bfile_desc,bfile_type FROM graphics_table;
BEGIN
OPEN get_id;
LOOP
FETCH get_id INTO id, bf_desc, bf_typ;
EXIT WHEN get_id%notfound;
dbms_output.put_line('ID: '||to_char(id));
SELECT bfile_loc INTO locator FROM graphics_table WHERE bfile_id=id;
dbms_lob.filegetname(
locator,bf_dir,bf_name);
dbms_output.put_line('Dir: '||bf_dir);
dbms_lob.fileopen(locator,dbms_lob.file_readonly);
bfile_len:=dbms_lob.getlength(locator);
dbms_output.put_line('ID: '||to_char(id)||' length: '||to_char(bfile_len));
SELECT temp_blob INTO image1 FROM temp_blob;
bfile_len:=dbms_lob.getlength(locator);
dbms_lob.loadfromfile(image1,locator,bfile_len,1,1);
INSERT INTO internal_graphics VALUES (id,bf_desc,image1,bf_typ);
dbms_output.put_line(bf_desc||' Length: '||TO_CHAR(bfile_len)||
' Name: '||bf_name||' Dir: '||bf_dir||' '||bf_typ);
dbms_lob.fileclose(locator);
END LOOP;
END;
/
Give this a read, http://aspalliance.com/570_Read_and_Write_BLOB_Data_to_a_Database_Table_with_ODPNET. The code sample is available for download as well.
I currently use Enterprise Library 2.0 to access the Oracle 9i. Everything works fine except when I need to insert Blob data. I noticed that OLE DB is used instead ODP.NET. I use binary to raw type conversion for the image date but it never worked. I don't have any problem to do so with ODP.NET. My question is, can I still able to do the same thing WITHOUT ODP.NET?
Can anyone advise me on this?
- ORA-01407: error when updating a record
- Convertion
- MySQL location MUST be in root directory?
- How to Display xml clob coming from a Oracle Database and display it on a web page.
- Connect to MySQL without odbc ?
- Unable to connect mySql
- clubing two columns
- Benchmark-Times
- oracle procedure, function and cursor from within VB
- Connecting to My SQL database
Rss Feed