Urgent : store and retrieve image to oracle database thru applet

hi all
i want the code sample for storing the image to oracle database
development enviornment:
server : oracle 9i , apache web server
client : ie6 browser
i am connecting to oracle database thru applet using oracle jdbc thin driver
can anyone give me details about storing image to db
1) what datatype should be used in table for image?
2) my image files are on client machine... can i directly read those files from browser or first i have to copy those files to server?
3) .gif files will do or what should be the fileformat?
4) java code to store it to database (i am using jdk1.3)
5) how to retrieve it back from database and display it in awt panel ?
its very urgent ...
i am doing some r&d and trying to do using blob....
but it will take some time ...
i will really be thankful if someone sends detail code....
thankx in advance ....

Hi,
The code below might answer few of your questions.
There is a restrcition on size of image, it must be less than 4KB.
//Code to insert image in database
//mytable is the table name that contains two fields in databse:name,image of type varchar and blob
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =null ;
Statement stmt =null ;
con =DriverManager.getConnection  ("jdbc:oracle:thin:@<hostname>:1521:orclsid", "system","manager");
PreparedStatement preparedStatement = con.prepareStatement("insert into mytable (name,image) values (?,?)");
preparedStatement.setString(1,"Amol");
InputStream inputStream = new BufferedInputStream(new FileInputStream("C:\\WINNT\\Temp\\netscape\\images\\menubg.jpg"));
preparedStatement.setBinaryStream(2, inputStream, inputStream.available());
preparedStatement.executeUpdate();
preparedStatement.close();
inputStream.close(); To retrieve image,here is the snippet
ResultSet resultSet = stmt.executeQuery("select image from mytable'");
if (resultSet.next())
byte[] image1 = resultSet.getBytes("image");
FileOutputStream fos=new FileOutputStream("c://splash11.jpg"); //will retrieve bytes and create a file
//by the name specified
fos.write(image1);
-Amol

Similar Messages

  • How to store and retrive images in oracle database

    hi,
    i am interested in storing some students pictures ( photos) into my oracle database, and i want to know since the images are considered as binary data and since BLOB and CBLOB and supported by oracle, how to insert and to select the picture from oracle from my swing-based application?
    does anyone have a complete sample or tutorial doing that well!!
    thx

    Mira este link,
    hay varios articulos interesantes.
    http://www.oracle-base.com/articles/9i/Articles9i.php
    tambien puedes consultar este link
    http://tahiti.oracle.com/pls/db92/db92.homepage
    completa los coampos solicitados con la palabra "Images"
    hay un manual de LOBs muy completo

  • Can you suggest a best way to store and read arabic from oracle database?

    Hi ,
    can you suggest a best way to store and read arabic from oracle database?
    My oracle database is Oracle Database 10g Release 10.1.0.5.0 - 64bit Production on unix HP-UX ia64.
    NLS_NCHAR_CHARACTERSET AL16UTF16
    NLS_LANGUAGE AMERICAN
    NLS_TERRITORY AMERICA
    NLS_CHARACTERSET WE8ISO8859P1
    I have presently stored the data in nvarchar2 field. But i am not able to display it correctly.

    Using the national characterset should work but there are other factors that you have to consider when working with NCHAR/NVARCHAR2/NCLOB.
    If possible, changing the characterset is usually the best solution if it's a possiblity for you.
    For more info:
    Dear Gurus: Can u pls explain the difference between VARCHAR2 & NVARCHAR2??

  • Store and retrieve image in database using WD Java

    Hi All,
    I have to store and retrieve an image in oracle database. I have gone through the below blog and forum...
    How to display an image, which is stored in a database?
    The specified item was not found.
    I am able to store image in byte format(oracle data type BLOB) and when i try to retrieve it i am not getting the image....Sorry for my poor technical knowledge.
    can some body help me, please......
    Regards,
    G.

    Hi,
    my code is working... I am able to upload and retrieve the image. But now I am getting the below exception...
    Exception from image insert>> java.sql.SQLException: Data size bigger than max size for this type: 6770
    Below is the code I am uing...
    ConnectDataBase condb=new ConnectDataBase();
        IWDMessageManager mgnr=wdComponentAPI.getMessageManager();
         IPrivateDBImageView.IVn_FileElement  fileelement =
                                  wdContext.nodeVn_File().getVn_FileElementAt(0);
                             IWDResource resource=wdContext.currentContextElement().getResource();
    InputStream in=resource.read(false);
    ByteArrayOutputStream bOut=new ByteArrayOutputStream();
                             int lenght=0;
                             byte part[]=new byte [ 50000 ];
                             while((lenght=in.read(part))!=-1)
                             bOut.write(part,0,lenght);     
              Statement  stmnt=null;
                   Connection con=null;
                   String strQuery=null;
                   String strProp_Details=null;
                   try {
                        con=condb.getConnection (mgnr);
                        stmnt=con.createStatement();
                   PreparedStatement pst=con.prepareStatement("insert into VMS_Image values(?,?,?)");
                        pst.setInt(1,4);
                        pst.setString(2,"srinu1234");
                        pst.setBytes(3,bOut.toByteArray());
                        pst.execute();
                        bOut.close();
                        in.close();
                        mgnr.reportSuccess("Inserted");
                   catch (SQLException e) {
         mgnr.reportException("SQLException from image insert>>"+e,false);
                   catch(Exception e)
                             mgnr.reportException("Exception from image insert>>"+e,false);     
                        finally
                        try
                        if(stmnt!=null)
                             stmnt.close();
                             stmnt=null;     
                        if(con!=null)
                             con.close();     
                             con=null;
                        catch(Exception e)
                             mgnr.reportException("Exception in Closing from image insert>>"+e,false);
    first I used byte of 101024, then 501024 and finally tried with byte of 50000. I am getting the above exception if the image size is more than 4kb....
    Regards,
    Srinivas.
    Edited by: srinivas sistu on Aug 1, 2008 2:26 PM
    Edited by: srinivas sistu on Aug 1, 2008 2:34 PM

  • How to store and retrieve images from database...

    Hi All
    Anubody tell me plz how to store images in database using jsp.
    and how to retrieve tme.
    Plz reply...
    Anurag

    Exactly
    try the links below may be those might help u in store and retrieval any kind of file.
    http://www.mysqltalk.org/insert-blob-example-vt112861.html
    https://java.sun.com/j2se/1.5.0/docs/guide/jdbc/blob.html
    http://javaalmanac.com/egs/java.sql/GetBlob.html
    http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.jdbc.doc/jdbc142.htm
    and a dearly advice friend please query google b4 you post any query out here.

  • I want to store and retrieve images from a oracle datrabase's BLOB type

    Hi all
    I am using WebLogic and Oracle 10g.I have to store images and retrieve them from a BLOB type.
    Please help .

    Please have a look to the Database Application Developer's Guide - Large Objects
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14249/toc.htm

  • How do i store and fetch image from the Database(Access)

    i am facing one problem in inserting the image into the database.the steps i followed as
    1)i have created one database(access) as "Image" and into that one table as "Image" and field as "image"
    type of the field is ole object.
    2)i have inserted one image into the image field through "database.vi"
    3)now i am trying to get the image from the database by "Fetching Example.vi"
    4)it will succesfully retrieve the image from that field .
    5)but when i close the both programs and reopen those that time i am unable to get retrieve the image.
    Attachments:
    Add_to_Database.vi ‏78 KB
    Fetch_from_database.vi ‏67 KB

    I would like to suggest different approach for saving the images in the database.
    I was working on Medical Imaging Company. The way we save the images in real-time was by writing the name and path of the images to database.
    The images themselves where saved directly to disk.
    I don�t think that access is very good in taking care of GBytes of data.
    It happens some time that the database gets damage. If you have the images separately you can create fix procedure. (We had one).
    Good Lack,
    Amit Shachaf,

  • Can i store and retrieve image using sql command?

    hi
    the following is what i enter to store image in table using sql*plus
    however i encounter some errors as shown below.
    i wondered if i actually can use sql to store image and retreive image
    or i need other developer beside sql to do.
    create table img_storage
    (id     number primary key,
    image     ORDSYS.ORDImage);
    CREATE or REPLACE procedure ADD_image (tmp_id number, file_name varchar2)
    as
         obj ORDSYS.ORDImage;
         ctx raw(4000) := null;
    begin
         INSERT INTO img_classifier (id, image) VALUES (tmp_id,
         ORDSYS.ORDImage (ORDSYS.ORDSOURCE(EMPTY_BLOB(),
         NULL,NULL,NULL,SYSDATE,NULL),
         NULL,NULL,NULL,NULL,NULL,NULL,NULL));
         COMMIT;
         SELECT image into obj FROM img_storage
         where id = tmp_id FOR UPDATE;
         obj.importFrom(ctx,'FILE','IMGDIR',file_name);
         obj.setproperties();
         UPDATE img_storage
         SET image = obj where id = tmp_id;
         COMMIT;
    end;
    show errors;
    create or replace directory imgdir as 'c:\image\';
    exec add_image(1,'argvseng.jpg');
    BEGIN add_image(1,'argvseng.jpg'); END;
    ERROR at line 1:
    ORA-00001: unique constraint (SYS.SYS_C002717) violated
    ORA-06512: at "SYS.ADD_IMAGE", line 7
    ORA-06512: at line 1
    how to reslove the error as shown above.
    or sql does not support ordsys.ordimage such command.
    hmm very confused ....
    what is the difference bet using blob for image and ordsys.ordimage?

    This has nothing to do with intereMedia.
    This is a basic SQL issue.
    A primary key cannot have duplicate entries in a table as the error message suggests.
    Before you call your peocedure you can delete the row with 1 as the primary key, or call the insert peocedure using a primary key that is not being used.

  • How to store and retrieve image in a MsAccess DB using JDBC

    I want to store images in a MsAccess DB using JDBC and also want retrieve them from DB. please don't tell to store the path of image..I want to store the image not the path...pls reply..thanx in advance

    zakircse, you should read more about Java's API.
    import java.io.*;
    import java.sql.*;
    import java.util.Properties;
    import java.awt.*;
    import javax.swing.*;
    public class ImageDemo{
    public static void main(String argv[]){
    try{
    String url="jdbc:access:/c:/test";
    Class.forName("com.hxtt.sql.access.AccessDriver").newInstance();
    Properties properties=new Properties();
    Connection connection = DriverManager.getConnection(url,properties);
    Statement stmt = connection.createStatement();
    stmt.execute("create database if not exists imagedatabase;");
    connection.setCatalog("imagedatabase.mdb");
    stmt.execute("create table if not exists imagetable (imageid int,IMAGE_DATA blob);");
    File file=new File("c:/pic.jpg");
    FileInputStream in=new FileInputStream(file);
    PreparedStatement ps=connection.prepareStatement("insert into imagetable (imageid,IMAGE_DATA) values(?,?);");
    ps.setInt(1,1234);
    ps.setBinaryStream(2,in,(int)file.length());
    ps.execute();
    ps.close();
    ResultSet rs =stmt.executeQuery("select IMAGE_DATA from imagetable where imageid=1234");
    byte[] imgbytes=null;
    if(rs.next()) {
    imgbytes=rs.getBytes(1);
    rs.close();
    stmt.close();
    connection.close();
    if(imgbytes!=null){
    JFrame fr = new JFrame();
    fr.setTitle("Simple Demo for Load Image from MS Access");
    Image image = fr.getToolkit().createImage(imgbytes);
    fr.getContentPane().add(new PaintPanel(image));
    fr.setSize(200,400);
    fr.setVisible(true);
    Thread.sleep(10000);
    System.exit(0);
    catch( SQLException sqle )
    do
    System.out.println(sqle.getMessage());
    System.out.println("Error Code:"+sqle.getErrorCode());
    System.out.println("SQL State:"+sqle.getSQLState());
    sqle.printStackTrace();
    }while((sqle=sqle.getNextException())!=null);
    catch( Exception e )
    System.out.println(e.getMessage());
    e.printStackTrace();
    class PaintPanel extends JPanel {
    private Image image;
    public PaintPanel(Image image) {
    this.image = image;
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(image, 0, 0, this);
    }

  • How to store and retrieve image in a apache derby using JDBC

    hi all
    this is source code i copy and modify but get error message like this
    import java.io.*;
    import java.sql.*;
    import java.util.Properties;
    import java.awt.*;
    import javax.swing.*;
    public class ImageDemo{
    public static void main(String argv[]){
    try{
    String url="jdbc:derby:derDB2";
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
    Properties properties=new Properties();
    Connection connection = DriverManager.getConnection(url,properties);
    Statement stmt = connection.createStatement();
    stmt.execute("create database if not exists imagedatabase");
    stmt.execute("create table if not exists imagetable (imageid int,IMAGE_DATA blob)");
    File file=new File("c:\\c.jpg");
    FileInputStream in=new FileInputStream(file);
    PreparedStatement ps=connection.prepareStatement("insert into imagetable (imageid,IMAGE_DATA) values(?,?)");
    ps.setInt(1,1234);
    ps.setBinaryStream(2,in,(int)file.length());
    ps.execute();
    ps.close();
    ResultSet rs =stmt.executeQuery("select IMAGE_DATA from imagetable where imageid=1234");
    byte[] imgbytes=null;
    if(rs.next()) {
    imgbytes=rs.getBytes(1);
    rs.close();
    stmt.close();
    connection.close();
    if(imgbytes!=null){
    JFrame fr = new JFrame();
    fr.setTitle("Simple Demo for Load Image from MS Access");
    Image image = fr.getToolkit().createImage(imgbytes);
    fr.getContentPane().add(new PaintPanel(image));
    fr.setSize(200,400);
    fr.setVisible(true);
    Thread.sleep(10000);
    System.exit(0);
    catch( SQLException sqle )
    do
    System.out.println(sqle.getMessage());
    System.out.println("Error Code:"+sqle.getErrorCode());
    System.out.println("SQL State:"+sqle.getSQLState());
    sqle.printStackTrace();
    }while((sqle=sqle.getNextException())!=null);
    catch( Exception e )
    System.out.println(e.getMessage());
    e.printStackTrace();
    class PaintPanel extends JPanel {
    private Image image;
    public PaintPanel(Image image) {
    this.image = image;
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(image, 0, 0, this);
    and this is the error message
    Syntax error: Encountered "database" at line 1, column 8.
    Error Code:30000
    SQL State:42X01
    ERROR 42X01: Syntax error: Encountered "database" at line 1, column 8.
         at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
         at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
         at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
         at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
         at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
         at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
         at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
         at ImageDemo.main(ImageDemo.java:28)

    It's complaining about this SQL in your code:create database if not exists imagedatabaseThat doesn't exactly look right to me. And perhaps "database" is a reserved word and can't be used in that position. At any rate I would recommend you create your database and tables in some other way before you write Java code to use them. Does Derby have a command-line interface or a GUI manager program? Use them if they exist to set up your tables.

  • How to store and retrieve chinese characters

    Hi, I am facing some problem in storing and retrieving of chinese characters from oracle,9i .
    This is the character i am trying to store into the database
    自动提款机网络
    while trying to retrieve it, it shows
    自?提款机网?
    ^ ^
    you can see the weird characters like ? at some places.
    here is the sample code which i can using to store and retrieve data from the database
    class testInsert
    public static void main(String[] args)
    try {
         DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
         Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@172.16.6.81:1521:JFPPTDB1", "citi_user", "citi_user");
         int employee_id = 12345;
    String ename = "自动提款机网络";
         oracle.jdbc.OraclePreparedStatement pstmt = (oracle.jdbc.OraclePreparedStatement)conn.prepareStatement("INSERT INTO employees (employee_id, last_name) VALUES (?, ?)");
         pstmt.setFormOfUse(2, oracle.jdbc.OraclePreparedStatement.FORM_NCHAR);
         pstmt.setInt(1, employee_id);
         pstmt.setString(2, ename);
         pstmt.execute();
    pstmt.close();
    pstmt = (oracle.jdbc.OraclePreparedStatement)conn.prepareStatement("SELECT last_name, employee_id from employees");
    ResultSet rset = pstmt.executeQuery();
              String name = "";
              while(rset.next())
                   name = rset.getString(1);
         int id = rset.getInt(2);
              System.out.println("the name is :"+name);
    catch (SQLException sqe)
              System.out.println("Java SQLException caught, error message="+sqe.getMessage());
    and the table in oracle is
    SQL> desc employees;
    Name Null? Type
    LAST_NAME NVARCHAR2(10)
    EMPLOYEE_ID NUMBER
    I am using classes12.zip for oracle,9i. Is there any database setting that i need to know to retrieve the chinese characters?.
    I have been facing this problem for quite sometime and it makes my life tough. Please help me in solving this issue.
    Thanks
    PD

    hi, can you retrieve the chinese character from your os? When it comes to the wild code of asian character, you should focus on the database/client character setting. you may ask more about it from your dba.
    have a nice weekend!
    eilison
    [email protected]

  • How to store image in oracle database and retrieve

    Hi i want to store a image in oracle database, user will select the image and i want tht image to store in database in java/jsp can anybody help

    try the following in yr app
    try{
    File fileObject = new File("img path");
    FileInputStream fisObject = new FileInputStream(fileObject);
    PreparedStatement pstmt =
    conn.prepareStatement("insert into IMG_TABLE values (?,?)");
    pstmt.setString(1,fileObject.getName());
    pstmt.setBinaryStream(2,fisObject,(int)fileObject.length());
    pstmt.executeUpdate();
    catch(SQLException se)
    se.printStackTrace();
    catch(Exception ee)
    ee.printStackTrace();
    }

  • How to store and retrieve blob data type in/from oracle database using JSP

    how to store and retrieve blob data type in/from oracle database using JSP and not using servlet
    thanks

    JSP? Why?
    start here: [http://java.sun.com/developer/onlineTraining/JSPIntro/contents.html]

  • Help abt store and delete images as blob & bfile using Visual C++

    Hi
    Does anyone knows if there is code for visual c++
    to store and delete images as blob or bfile?
    thanx

    The documentation states there are examples in the oracle database distribution: <ORACLE_HOME>/rdbms/demo/cdemolb.c <ORACLE_HOME>/rdbms/demo/cdemolb2.c <ORACLE_HOME>/rdbms/demo/cdemolbs.c
    These examples are in c, but can be used in c++
    http://otn.oracle.com/doc/server.815/a67846/app_exam.htm#430289

  • Want to store and retrived  images  in the BFILE format using inter media

    I want to store and retrived images in the BFILE format using inter media.I found a article in the oracle site that Oracle interMedia image supports BFILEs.But this article is not demonstrating the use of BFILEs.Please help me to findout the solution.
    Thanks in advance.
    null

    The advantage to using BFILE storage for your is that it's an easy way for Oracle
    Multimedia to access your images without importing them into the database.
    The disadvantages are that the images are read-only. If you want to scale an image or
    convert to a different format, you will need to create a destination image to hold the result. This
    will necessarily be a BLOB based image.
    Adding images is difficult to do from within an application program. Generally you would add new images to a file system that is accessible to the Oracle Database, then insert new rows in your table with appropriate BFILE pointers to the new images.
    BFILE images require separate backup from the database. Also there is not way to transactionally coordinate your BFILE data with your relational data.
    If you are using Oracle 11g, you can use the SecureFile option for BLOB storage. This is much faster then the previous BLOB storage (now called BasicFile) and much faster then BFILE also.
    That said, below is a code snippet that shows how to insert a BFILE based image, set it's properties, show it's properties and select the BFILE locator to access the content. You would need to use the DBMS_LOB package (in PL/SQL) to read the content. From other APIs, (e.g., Java) you would need to use the proper interfaces to access the BFILE.
    Note that you need change the USER, PASSWORD fields in the code. Also you should change the directory location and image name for your use.
    -- create a directory object indicating where the images are stored;
    create or replace directory imgdir as '/tmp';
    -- and grant permission to read to a user;
    grant read on directory imgdir to <USER>;
    conn <USER>/<PASSWORD>;
    -- create the images table
    create table images(id integer primary key, image ordsys.ordimage);
    set serveroutput on
    declare
    obj ordsys.ordimage;
    begin
    -- use the init('FILE', <SRC_LOCATION>, <SRC_FILE>) function
    -- to create an ORDIMAGE object with a BFILE source
    insert into images(id, image)
    values(1, ordimage.init('FILE', 'IMGDIR', 'wizard.jpg'))
    returning image into obj;
    -- lets see if the image source is local or not
    if(obj.isLocal()) then
    dbms_output.put_line('image source is local');
    else
    dbms_output.put_line('image source is NOT local');
    end if;
    -- set the properties of the image object
    obj.setProperties();
    -- and update the row
    update images set image=obj where id=1;
    commit;
    end;
    column height format 99999
    column width format 99999
    column mimetype format a30
    column length format 999999
    -- let's see what we have
    select t.image.getHeight() as "height"
    , t.image.getWidth() as "width"
    , t.image.getMimetype() as "mimetype"
    , t.image.getContentLength() as "length"
    from images t
    -- fetch a BFILE handle to the content
    declare
    bf BFILE;
    length number;
    begin
    select t.image.getBfile() into bf
    from images t
    where t.id=1;
    -- use the DBMS_LOB interface to find out size of image
    length := dbms_lob.getLength(bf);
    dbms_output.put_line('length of BFILE is ' || length);
    end;
    ---What we get when we run the code
    Connected.
    Directory created.
    Connected.
    Table created.
    image source is NOT local
    PL/SQL procedure successfully completed.
    height     width mimetype               length
    399     485 image/jpeg          92552
    length of BFILE is 92552
    PL/SQL procedure successfully completed.
    SQL>

Maybe you are looking for