Display images stored in the database

I have images stored in the databse. I followed the steps provided in the oracle documentation. Now i want to retrive the image from the database into a java object that can be dislayed in , say, a JLabel. I am able to retrieve the image from the database into the OrdImage in the oracle.java.ord package and view the properties of the image. But unable to retrive the image as such to be displayed.
Thanking You
vinay

This might help...
import javax.imageio.*;
import javax.imageio.stream.*;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
import oracle.sql.* ;
import oracle.ord.im.*;
import java.awt.event.*;
public class HelloDBImage implements ActionListener{
OracleConnection con = null;
JLabel label = null;
String textFieldString = "Image ID entered";
public void actionPerformed(ActionEvent e)
String prefix = "You typed \"";
if (e.getActionCommand().equals(textFieldString))
JTextField source = (JTextField)e.getSource();
ImageIcon imgIcon = createImageIcon(source.getText());
if (null != imgIcon)
// Create image Label
label.setText(null);
label.setIcon(imgIcon);
else
label.setIcon(null);
label.setText("Image not found! ");
source.setText("");
label.repaint();
//actionLabel.setText(prefix + source.getText() + "\"");
public ImageIcon createImageIcon(String key)
Image image = null;
ImageIcon imgIcon = null;
try
     // Connect to the database if necessary
if (null == con) con = connect();
// Create Input Stream from DB image.
InputStream is = new BufferedInputStream(
getDBInputStream(con, key));
if (null != is)
// Create Image from Image Input Stream
ImageInputStream iis = ImageIO.createImageInputStream(is);
image = ImageIO.read(iis);
// Create Image Icon from ImageInputStream
if (null != image) imgIcon = new ImageIcon(image);
} catch (Exception e)
System.out.println("exception raised " + e);
     e.printStackTrace();
return imgIcon;
public Component createPanelAndContents(String key)
// Create the image label
ImageIcon imgIcon = createImageIcon(key);
if (null != imgIcon)
// Create image Label
label = new JLabel(imgIcon);
else
label = new JLabel("Image not found! ");
// Create layout
GridBagLayout gridBag = new GridBagLayout();
// Create panel to draw in
JPanel pane = new JPanel();
pane.setLayout(gridBag);
GridBagConstraints c = new GridBagConstraints();
JScrollPane scrollPane = new JScrollPane(label,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
gridBag.setConstraints(scrollPane, c);
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
scrollPane.setMinimumSize(new Dimension(300, 300));
pane.add(scrollPane, c);
// Add a text field and label to get anoter image
JTextField textField = new JTextField(10);
textField.setActionCommand(textFieldString);
textField.addActionListener(this);
// Add fields for input
JLabel promptLabel = new JLabel("Please enter DB key: ");
     pane.add(promptLabel);
pane.add(textField, c);
return pane;
public static void main(String[] args)
String key = "1";
try
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) { }
//Create the top-level container and add contents to it.
JFrame frame = new JFrame("SwingApplication");
HelloDBImage app = new HelloDBImage();
if ((args.length > 0) && (args[0] != null)) key = args[0];
System.out.print("length= " + args.length + "/" );
if (args.length > 0) System.out.println(args[0]);
Component contents = app.createPanelAndContents(key);
frame.getContentPane().add(contents, BorderLayout.CENTER);
//Finish setting up the frame, and show it.
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
frame.pack();
frame.setVisible(true);
public InputStream getDBInputStream(OracleConnection con, String key)
InputStream is = null;
try
     int index = 0;
     Statement s = con.createStatement();
     OracleResultSet rs =
     (OracleResultSet)s.executeQuery("select * from images " +
"where item_id = " + key );
     if (rs.next()) // Just get first image if more than 1.
     index = rs.getInt(1);
     OrdImage imgObj =
(OrdImage) rs.getCustomDatum(2, OrdImage.getFactory());
is = imgObj.getContent().getBinaryStream();
catch(Exception e)
System.out.println("exception raised " + e);
e.printStackTrace();
return is;
public OracleConnection connect() throws Exception
String connectString;
Class.forName ("oracle.jdbc.driver.OracleDriver");
connectString = "jdbc:oracle:oci8:@orcl";
OracleConnection con = (OracleConnection)
DriverManager.getConnection(connectString,"scott",
                    "tiger");
con.setAutoCommit(false);
return con;

Similar Messages

  • Displaying images stored in the database

    Hi,
    I'm saving image files (bmp, jpg, gif) in the database as binary data (I'm using SQL Server). Then, I have to retrieve this file and show the image in a JSP.
    I'm using Struts 1.1, SQLServer and weblogic.
    How can I do this?
    Thanks

    Here is a good starting point:
    http://forum.java.sun.com/thread.jsp?thread=338890&forum=45&message=1391475

  • Can Discoverer have link to display documents stored outside the database?

    I posted a message some time ago called "Possible for Discoverer to display BLOB type documents stored in database?" and got great answer.
    Now our customers are asking if it is possible, from Discoverer, to link somehow to a file stored outside the database on the Unix file system and get their computer to display it? Can anyone tell me if this is possible please?
    The only thing I've seen in the documentation that may be related is in Oracle Business Intelligence Discoverer Configuration Guide, section 10.6 List of Discoverer user preferences. It says there that Discoverer preference ProtocolList can be set so that Discoverer hyperlinks can be set to use protocols such as telnet, but the default is HTTP, HTTPS, and FTP.
    THank you in advance if you can help.
    Regards,
    Julie.

    Hi Rod,
    I have tried the second method: "create a Oracle directory pointing to the Unix directory containing the files". I have had success with it, but I'd be grateful if you could advise me if you would have done this the same way as described below:
    I put two Word docs and two text docs called clob_test1.txt, clob_test2.txt, blob_test1.doc, blob_test2 in the Unix directory corresponding to an Oracle directory called 'EIF'. I thought an extrenal table was needed so that Discoverer would have an object to write a queruy against. So I created a file called lob_test_data.txt with the following contents:
    1,01-JAN-2006,text/plain,clob_test1.txt
    2,02-JAN-2006,text/plain,clob_test2.txt
    3,01-JAN-2006,application/msword,blob_test1.doc
    4,02-JAN-2006,application/msword,blob_test2.
    THen I created an external table using the following DDL:
    CREATE TABLE jum_temp_lob_tab (
    file_id NUMBER(10),
    date_content DATE,
    mime_type VARCHAR2(100),
    blob_content BLOB
    ORGANIZATION EXTERNAL
    TYPE ORACLE_LOADER
    DEFAULT DIRECTORY EIF
    ACCESS PARAMETERS
    RECORDS DELIMITED BY NEWLINE
    BADFILE EIF:'lob_tab_%a_%p.bad'
    LOGFILE EIF:'lob_tab_%a_%p.log'
    FIELDS TERMINATED BY ','
    MISSING FIELD VALUES ARE NULL
    file_id CHAR(10),
    date_content CHAR(11) DATE_FORMAT DATE MASK "DD-MON-YYYY",
    mime_type CHAR(100),
    blob_filename CHAR(100)
    COLUMN TRANSFORMS (blob_content FROM LOBFILE (blob_filename) FROM (EIF) BLOB)
    LOCATION ('lob_test_data.txt')
    PARALLEL 2
    REJECT LIMIT UNLIMITED
    then created a Discoverer End User Layer folder against this external table, and used exactly the same technique as we did for downloading the BLOB from the database table (creating a new folder item containing a URL calling a database procedure which calls the Oracle code to download the doc). THis worked, but sometimes my PC didn't seem to know that the Word docs were Word docs and it needed to launch Word. Other times it did manage to do this OK. It always displayed the two .txt files as HTML docs.
    Just wondered if you'd be good enough to critique this approach.
    THank you, Julie.

  • How to display Images stored in a database using javascript

    Hi.
    I have some images stored in a table and I need to display them using javascript. The images are stored in BLOB columns: I would like to know if I can put them on a directory and then get it from there using BFILENAME function.
    Any suggestion?
    Regards,
    Jeannine

    Hi All,
    Yes DuraiRaja - i am using the document.getElementById(' ').
    In my app, I have a Main controller calling a View - Default.HTM,
    This Default.HTM, in turn loads up three trays T1, T2, T3 and these tray elements in turn call up the controllers ctrl1, ctrl2, ctrl3 associated to them.
    CTRL1 calls a view - View1 - V1.htm, which has the below code.
    And on the below page all that i am trying to do is validate if "FieldVal" is blank or not.
    I get an error on IE as "Object required"
    I get a HTTP 501/505 error when i try to upload the code.
    Thanks all !

  • Display HTML stored in the database

    Hi
    CREATE TABLE source
    (sql_text CLOB
    The content of sql_text is text surrounded by various HTML-tags.
    Which options do I have for displaying sql_text formatted according to the HTML-tags? In other words how can I get apex to send the content of sql_text to the browser with out escaping the tags?
    Marius

    Since I haven't found a way to list a report (more than one row from the database), I ended up using a Display as Text (does not save state) and the following SQL as source
    SELECT CONCATINATION(CURSOR(SELECT somecolumn FROM sometable ORDER BY order_key)) FROM DUAL;
    CREATE OR REPLACE FUNCTION CONCATINATION(l_cursor IN SYS_REFCURSOR, seperator IN VARCHAR2 default '<BR>') RETURN clob
    IS
    string clob;
    sub_string clob;
    BEGIN
    LOOP
    FETCH l_cursor INTO sub_string;
    EXIT WHEN l_cursor%notfound;
    IF l_cursor%ROWCOUNT = 1 THEN
    string := sub_string;
    ELSE
    string := string || seperator || sub_string;
    END IF;
    END LOOP;
    RETURN string;
    END;
    Edited by: Marius2 on Mar 23, 2009 8:37 PM
    Fixed a small bug

  • Displaying .jpg images stored in the database

    I created a table and a form to store .jpg images then display the .jpg files in a dynamic page.
    I can insert the images and display the dynamic page but selecting the HREF link will not dispaly the .jpg file.
    I used the Metalink DocID: Note:68016.1 Subject:Browsing database image objects to create the package.
    The package code is as follows
    Create or Replace PACKAGE OREF.IMG
    as
    PROCEDURE select_img_table;
    PROCEDURE retrieve_img_data(img_id varchar2);
    end;
    Create or Replace PACKAGE BODY OREF.IMG
    AS
    PROCEDURE select_img_table AS
    CURSOR c1 IS SELECT id, name FROM filestore;
    BEGIN
    htp.bodyopen;
    FOR i IN c1 LOOP
    htp.print(TO_CHAR(i.id));
    htp.print(i.name);
    htp.anchor('../../pls/oref/IMG.retrieve_img_data?img_id='||to_char(i.id),'jpg',null,null);
    htp.br;
    htp.bodyclose;
    END LOOP;
    END select_img_table;
    PROCEDURE retrieve_img_data(img_id varchar2) AS
    Lob_field BLOB;
    buffer RAW(32767);
    offset BINARY_INTEGER:=1;
    buffer_size NUMBER:=32767;
    BEGIN
    SELECT object INTO lob_field FROM filestore WHERE id=img_id;
    OWA_UTIL.MIME_HEADER('image/jpg');
    LOOP
    DBMS_LOB.READ(lob_field,buffer_size,offset,buffer);
    htp.prn(UTL_RAW.CAST_TO_VARCHAR2(buffer));
    offset:=offset+buffer_size;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    null;
    END retrieve_img_data;
    END img;
    *The dynamic page Code is as follows:
    <HTML>
    <HEAD>
    <TITLE>Display Filestore Table</TITLE>
    </HEAD>
    <BODY>
    <H2>Display of .jpg files in the Filestore Table</H2>
    <ORACLE>select id, ''||name||''
    from oref.filestore</ORACLE>
    </BODY>
    </HTML>

    You'll need to provide a full URL link to the image ("http://mywebserver/file/images_personnel/28.jpg"), not just a relative path.  Remember, the email client that is used to view the email content knows nothing of the internals of your web server - it can only follow a complete URL to get images and other resources.
    -Carl V.

  • How to view images stored in the database

    Hi all
    I've a table in the db lets say T and two cols (ID & IMAGE). IMAGE data type is ORDIMAGE. I want to view this image in the web browser using the Dyanmic Page in Oracle Portal. Please anyone help me.
    Regards

    query = "Select * From (SELECT *,COUNT(1) OVER (PARTITION BY ENo) AS Occur FROM EmpLeave)t Where Occur >1)";
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Image compressed and stored in the database.

    Hi,
    We have a tiff file stored in the database and then compressed using the following Intermedia Oracle method.
    process ('compressionFormat=FAX4,maxScale=1696 2200'); and save it back in the database.
    This oracle database is 8.1.7.4. The tiff file gets processed when we use TIFF file generated by old scanner but errors out with the TIFF file generated by latest scanners.
    The error I get is ORA 29400 , IMG-00704.
    There is a difference in TIFF version in the outputs generated by two scanners,
    The compression option : TIFF modified G3 in the old one
    while the new one has Lempel-Ziv
    Also, the tiff is loaded and saved fine but the image gets corrupted after the intermedia process method is run.

    Thank you for your reply.  I am glad to find that I did not miss an option.  I was aware that I could move my pictures into some other folder, but you have forgotten the solution that I chose.  That was to go back and use ZoomBrowser, which works to access photos in any folder I choose.  In addition it loads promptly.  I have only spent a brief time using the ImageBrowser but don't recall seeing any enhancements that over ZoomBrwoser.  Perhaps if I was attempting to interface with other software but as a stand-alone product, well perhaps you could enlighten me as to what makes ImageBrowser EX a better product..  Regarding the Accept as Solution: are you implying that Canon restricts their search function to only those responses that the OP marks as accepted?

  • Best ways to view/display PDF/Excel files stored in the Database

    What are best ways to display/view PDF/Excel files stored in the Database? thanks L

    Thanks tom, sorry let me explain. Currently we have oracle forms screen, using webutil to store/view files into DB. client won't like the interface, they want us to make it more friendly, drag and drop if possible, load multiple files, as possible.. So I am exploring different ways to improve may be java (or jdev/any any other), different screen designs, different features for fileupload/download/view options.

  • Oracle reports to display PDF/Excel files stored in the Database

    can we use Oracle reports to view/display PDF/Excel files stored in the Database? Thanks Lalitha

    A document stored in the database can be easily retrieved in or via the browser using mod_plsql. Simplified:
    select content, mime_type
    into v_blob, v_mime_type
    from ...
    owa_util.mime_header(nvl(v_mimetype,'application/octet'),false);
    htp.p('Content-length: ' || dbms_lob.getlength(v_blob));
    owa_util.http_header_close;
    wpg_docload.download_file(v_blob);So, the link in your report should point to this database procedure.
    Edited by: InoL on Mar 1, 2011 4:17 PM

  • Displaying images stored in SQL Server

    Is there someway of displaying images stored within SQL
    Server. Is FDS required? Prefer a method to display images without
    using FDS; Web Service would be okay if that can work

    I do that sort of thing using PHP and mySQL the binary part
    of the image is stored in a BLOB field (Binary Large OBject) along
    the rest of the information necessary for the http headers (e.g.
    mime type, file name, file size) being staored in their own fields.
    That info is then used to build the file using PHP. The PHP
    file contains a mySQL query whos result is echoed with the
    appropriate headers. The URL points at the PHP file rather than at
    any saved image.
    Here's the php:
    <?
    # display_imagebank_file.php
    # Note: the ID is passed through the url e.g.
    # this_files_name.php?id=1
    # connect to mysql database
    mysql_connect('HOST', 'USERNAME', 'PASSWORD');
    mysql_select_db('DATABASE');
    # run a query to get the file information
    $query = mysql_query("SELECT FileName, MimeType, FileSize,
    FileContents FROM blobTable WHERE ID='$id'");
    # perform an error check
    if(mysql_num_rows($query)==1){
    $fileName = mysql_result($query,0,0);
    $fileType = mysql_result($query,0,1);
    $fileSize = mysql_result($query,0,2);
    $fileContents = mysql_result($query,0,3);
    header("Content-type: $fileType");
    header("Content-length: $fileSize");
    header("Content-Disposition: inline; filename=$fileName");
    header("Content-Description: from imagebank");
    header("Connection: close");
    echo $fileContents;
    }else{
    $numRows = mysql_num_rows($query);
    echo "File not found <br>";
    echo $numRows;
    echo " is the number of rows returned for id = ";
    echo $ID;
    ?>
    Hope that helps
    Phil

  • Evaluation of html stored in the database

    Hello everyone, here is my story.
    I have html stored in the database that I am using in regions. The region is a pl/sql anonymous block with code similar to this.
    DECLARE
    testt varchar(30000);
    BEGIN
    SELECT Main_Page_Image_Zone INTO testt FROM htmltable where Main_Page_Image_Zone IS NOT NULL;
    htp.p(testt);
    END;
    It draws in and displays the html great. The only problem is apex isn't evaluating the html. I have an image that is drawing from #workspace_images#, but instead of translating this to something useful, I get a red x. It is trying to find the image as #workspace_images#...The html being drawn in isn't being evaluated like I want it to (I want it to translate #workspace_Images#). Any ideas how to evaluate this html?
    Here is what the image location is supposed to look like
    http://127.0.0.1:8080/apex/wwv_flow_file_mgr.get_file?p_security_group_id=6933527329162765&p_fname=fmw.gif
    Instead this shows up:
    http://127.0.0.1:8080/apex/f?p=104:12:617607226208594:::::#WORKSPACE_IMAGES#fmw.gif
    This is stored in the database (ignore the .)
    <.img src="#WORKSPACE_IMAGES#fmw.gif" width="697" height="439" border="0" usemap="#Map" />

    However
    Replacing occurences of '#WORKSPACE_IMAGES' with 'WORKSPACE_IMAGES' in the database
    and then applying the replace function on the column works.
    select replace(f1,'WORKSPACEIMAGES','&WORKSPACE_IMAGES.') into str from temp_tab;
    Again, don't know why !

  • Display images from a SQL database

    I want to display images from a SQL database. The images are in a table under a specific column and are stored as a link to the image. How would I display the images from the column in LabVIEW?
    I'm using LabVIEW 2013 version 13 and SQL Server 2012
    Paul Power
    I have not lost my mind, it's backed up on a disk somewhere

    Hi PauldePaor,
    I hope you are well.
    Once you have pulled the data from the database into LabVIEW in a string form (or path), you can simply use the Read BMP File (Or jpg, png depending on the file type) VI.
    More information can be found here:
    http://digital.ni.com/public.nsf/allkb/02971A30F5D8FC6986256A0A004F11A0
    Kind Regards,
    Aidan H
    Applications Engineer
    National Instruments UK & Ireland

  • Display image stored @ content managemenbt

    Hi,
    this is regarding to displaying image stored @ content management, using <html:img> tag in .jsp
    under a node i am uploading two images. (node having two upload options)
    in .jsp i am using <html:img> tag to display the images.
    i tried to display both the images. But the first image what i upload is not showing. what i upload second is displaying.
    pls let me know how to resolve this.
    Thanks.

    You need to access binary property values separately from the node. In 9.2 the API is accessed via INodeManager.getStream(). Alternatively you can take advantage of the tags we have for this as well. Take a look here on edocs:
    http://e-docs.bea.com/wlp/docs92/cm/developCM.html
    -Ryan

  • How to display "Image" object in the browser?

    can anyone please tell me how can i display "Image" object in the browser?
    I have an image object that i retrieved from AS400 BLOB object by using toolbox.jar (for as400 access for java including all necessary classes like jdbc driver, security etc.).
    i want to display this object in the browser so i will be able to web-enable my BLOB objects stored on as400.thx...

    In your HTML:
    <img src="ImageServlet">
    In ImageServlet:
    Make calls to DB to get your image as byte array and store it in:
    byte[] buffer = new byte[imageSize];
    ServletOutputStream out = response.getOutputStream();
    for(int i = 0; i < imageSize; i++)
    out.write(buffer, i, 1);
    out.close();

Maybe you are looking for

  • Hp 2540 air print

    Just got an iPad Air plus a 2540 deskjet because it supports Airprint. However.. the pad cannot see the printer. The PC prints wirelessly, the Mac prints to an IP address but no tablet printing. The support for Air print on the support site is non-ex

  • Monitoring Index without rows in v$object_usage !!!

    Hello Gurus, OS - Solaris Oracle - 92 I was generating a ddlscript to start monitoring index usage, I've run the sql below : @db92 > alter index INTRANET.PK_OWPDO MONITORING USAGE 2 ; Index altered. When I query the table V$OBJECT_USAGE i don't see a

  • Problem with Currency Field?

    Hello Friends, I have a currency fields in a Screen, When it's value is null, It is showing me as SPACE. But My requirement is to display 0.00. How can I do this? Please do the favour needful. Thanks & Regards Sathish Kumar.

  • Existing exchange installation re-join to domain

    Hello Everyone, I'm just trying learn by doing, amateur with active directory and a complete newbie to exchange. Here's the scenario and issue: Had setup a domain with a single DC Had installed a separate server with exchange, configured and working

  • How to save requisitions without using E-Recruiting

    Hello All, Is there a way, to save requisitions data without using the E-Recruiting Web pages? Is there a Function module or a Class or a BAdI that I can use? We want to use a Interface that will send a flat fille with a lot of data and then to handl