How to insert an image into DataBase? and also retrieving

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivapadma
    New Member
    • Mar 2007
    • 40

    How to insert an image into DataBase? and also retrieving

    I want to insert an image into DB.(using JSp)

    I want insertion and retriving using setBlob() and getBlob() methods.

    if anyone knows this ,please,reply me
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by shivapadma
    I want to insert an image into DB.(using JSp)

    I want insertion and retriving using setBlob() and getBlob() methods.

    if anyone knows this ,please,reply me
    Check for DBMS_LOB package

    Comment

    • subashsavji
      New Member
      • Jan 2008
      • 93

      #3
      Originally posted by shivapadma
      I want to insert an image into DB.(using JSp)

      I want insertion and retriving using setBlob() and getBlob() methods.

      if anyone knows this ,please,reply me
      [code=oracle]
      create or replace directory ctemp as 'c:\';
      [/code]

      [code=oracle]
      CREATE TABLE pdm (
      dname VARCHAR2(30), -- directory name
      fname VARCHAR2(30), -- file name
      iblob BLOB) -- image file
      [/code]

      [code=oracle]
      CREATE OR REPLACE PROCEDURE load_file (
      pdname VARCHAR2,
      pfname VARCHAR2) IS
      src_file BFILE;
      dst_file BLOB;
      lgh_file BINARY_INTEGER;
      BEGIN
      src_file := bfilename('CTEM P', pfname);
      -- insert a NULL record to lock
      INSERT INTO pdm
      (dname, fname, iblob)
      VALUES
      (pdname, pfname, EMPTY_BLOB())
      RETURNING iblob INTO dst_file;
      -- lock record
      SELECT iblob
      INTO dst_file
      FROM pdm
      WHERE dname = pdname
      AND fname = pfname
      FOR UPDATE;
      -- open the file
      dbms_lob.fileop en(src_file, dbms_lob.file_r eadonly);
      -- determine length
      lgh_file := dbms_lob.getlen gth(src_file);
      -- read the file
      dbms_lob.loadfr omfile(dst_file , src_file, lgh_file);
      -- update the blob field
      UPDATE pdm
      SET iblob = dst_file
      WHERE dname = pdname
      AND fname = pfname;
      -- close file
      dbms_lob.filecl ose(src_file);
      END load_file;[/code]
      [code=oracle]
      EXECUTE load_file('CTEM P','zak.gif');
      [/code]
      /
      note:- 'zak.gif' file must present in c:\ drive where you created directory.
      then use any front end tool ex. form 6i to retrieve the image
      Last edited by debasisdas; Feb 12 '08, 11:14 AM. Reason: added code=oracle tags

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        You need to convert the image file into a stream pf bytes and store in database.

        At the time of retrieval you need to construct the file from the stream of bytes.

        Comment

        • subashsavji
          New Member
          • Jan 2008
          • 93

          #5
          Originally posted by shivapadma
          I want to insert an image into DB.(using JSp)

          I want insertion and retriving using setBlob() and getBlob() methods.

          if anyone knows this ,please,reply me
          [code=oracle]
          create or replace directory my_files as 'C:\';[/code]
          /
          [code=oracle]
          CREATE OR REPLACE procedure load_a_file( p_id in number,
          p_filename in varchar2 )
          as
          l_clob clob;
          l_bfile bfile;
          begin
          insert into demo values ( p_id, empty_clob() )
          returning theClob into l_clob;
          l_bfile := bfilename( 'MY_FILES', p_filename );
          dbms_lob.fileop en( l_bfile );
          dbms_lob.loadfr omfile( l_clob, l_bfile,
          dbms_lob.getlen gth( l_bfile ) );
          dbms_lob.filecl ose( l_bfile );
          end;
          [/code]
          [code=oracle]
          EXECUTE load_a_file(2,' YY.TXT');
          [/code]

          Comment

          Working...