How to display a blob as an image

I am working on an application which stores images in a database as blobs. I need to extract these images and display them from a web page. How do I go about this using JSP or JSF?
Werner

Thanks for the quick response, matlas. I should have included more info in my original post. I am familiar with reading/writing blobs from the database. The part I am stuck on is how does the java servlet return the blob (dPhoto below), to the web page?
i.e. from <img src="employeePhoto.jsp&empId=123">
ImageIcon dPhoto = null;
// open connection
Connection photoConnection = startup.openSQLConnection(SQLDriver, SQLConnectionString);
// setup select string
String sqlStatement = "select Binary_Photo from employeephoto where Employee_ID = '"+employeeID+"'";
try {
// perform select
ResultSet rs = photoConnection.createStatement().executeQuery(sqlStatement);
// if record found process blob
if (rs.next()) {
// get blob
Blob image = rs.getBlob("Binary_Photo");
// setup the streams to process blob
InputStream input = image.getBinaryStream();
ByteArrayOutputStream output = new ByteArrayOutputStream();
// set read buffer size
byte[] rb = new byte[1024];
int ch = 0;
// process blob
while ((ch=input.read(rb)) != -1) {
output.write(rb, 0, ch);
// transfer to byte buffer
byte[] b = output.toByteArray();
input.close();
output.close();
// load final buffer to image icon
dPhoto = new ImageIcon(b);
catch (Exception exc) {/ do your exception processing}
// close connection
startup.closeSQLConnection(photoConnection);
// dPhoto holds image or is null at this point.

Similar Messages

  • How to display a BLOB column in ADF.

    How to display a BLOB column in ADF.

    hi agowlikar786
    Maybe the forum thread "ADF BC : download BLOB " can help
    at ADF BC : download BLOB
    regards
    Jan

  • How to display a blob image in RTF template's Header.

    Hi,
    I want to display a blob image (logo company) in my RTF template,
    my problem is how i can display this image in the template's Header.
    I tried this
    <?
    <fo:instream-foreign-object content-type="image/jpeg" >
    <xsl:value-of select=".//LOGO"/>
    </fo:instream-foreign-object>
    ?>
    but was unsuccessful
    Thanks in advance.

    I tried this
    <?
    <fo:instream-foreign-object content-type="image/jpeg" >
    <xsl:value-of select=".//LOGO"/>
    </fo:instream-foreign-object>
    ?>
    but was unsuccessful
    sure
    what is red elements ?
    you template can be looks like
    ..... some data .....
    ( after  all data )
    <?template:footer_logo?>
    <fo:instream-foreign-object content-type="image/jpeg" ><xsl:value-of select=".//LOGO"/></fo:instream-foreign-object> (as field )
    <?end template?>
    <?call-template:footer_logo?> ( in header/footer )
    some remarks https://oralublog.wordpress.com/2014/10/04/bi-publisher-11g-footers-and-headers-in-rtf-template/

  • How to display non-URL-based thumbnail images in JTable

    I'm trying to display thumbnail images as a tooltip popup for certain cells in a JTable. The thumbnail images are java image objects that have been retrieved dynamically as the result of a separate process--there is no associated URL. For this reason, I can't use the setToolTipText() method of the JTable.
    My attempts to JTable's createToolTip() method also failed as it seems the ToolTipManager never calls this method for a JTable.
    As a workaround, I've added a MouseMotionListener to the JTable that detects when the mouse is over the desired table cells. However, I'm not sure how to display the popup over the JTable. The only component that I can get to display over the JTable is a JPopupMenu, but I don't want to display a menu--just the image. Can anyone suggest a way to display a small popup image over the table?
    Thanks.

    Thank You Rodney. This explains why my createToolTip() method wasn't being called, but unfortunately I'm no closer to my goal of displaying a true custom tooltip using a non-URL image rather than a text string. If I make a call to setToolTipText(), at any point, the text argument becomes the tooltip and everything I have tried in createToolTip() has no effect. However, as you pointed out, if I don't call setToolTipText(), the table is not registered with the tooltip manager and createToolTip() is never even called.
    To help clarify, I have attached an SSCCE below. Please note that I use a URL image only for testing. In my actual application, the images are available only as Java objects--there are no URLs.
    import javax.swing.*;
    import java.awt.*;
    import java.net.URL;
    import java.net.MalformedURLException;
    public class Test {
        static Object[][] data = {
                {"Cell 0,0", "Cell 0,1"},
                {"Cell 1,0", "Cell 1,1"}};
        static String[] columnNames = {"Column 0", "Column 1"};
        static JFrame frame;
        static String testImageURLName = "http://l.yimg.com/k/omg/us/img/7c/0a/4009_4182164952.jpg";
        static JTable testTable = new JTable(data, columnNames) {
            public JToolTip createToolTip() {
                System.out.println("testTable.createToolTip() called");
                Image testImage = getTestImage();
                // this.setToolTipText("Table ToolTip Text");
                JLabel customTipLabel = new JLabel(new ImageIcon(testImage));
                customTipLabel.setToolTipText("Custom ToolTip Text");
                JToolTip parentTip = super.createToolTip();
                parentTip.setComponent(customTipLabel);
                return parentTip;
        // This image is loaded from a URL only for test purposes!!!
        // Ordinarily, the image object would come from the application
        // and no URL would be available.
        public static Image getTestImage() {
            try {
                URL iconURL = new URL(testImageURLName);
                ImageIcon icon = new ImageIcon(iconURL);
                return icon.getImage();
            catch (MalformedURLException ex) {
                JOptionPane.showMessageDialog(frame,
                        "Set variable \"testImageName\" to a valid file name");
                System.exit(1);
            return null;
        public static void main(String[] args) throws Exception {
            frame = new JFrame("Test Table");
            frame.setSize(300, 100);
            // Set tool tip text so that table is registered w/ tool tip manager
            testTable.setToolTipText("main tooltip");
            frame.getContentPane().add(testTable);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }

  • How to display PDF BLOB file within Forms

    Hi All:
    I just want to know if is it possible to display PDF blob file within the forms. Currently I use webutil to open pdf in browser. This time I need to display it in forms, so that upon scrolling, the user can view the pdf images of that particular record.
    TIA

    Hello,
    <p>Did you see this Java Bean ?</p>
    Francois

  • Displaying a blob into an image on OAF Page

    Hi everyone,
    I read this topic Re: Displaying an Image stored in the Database as BLOB on OA Fwk Page
    but is there another way to display a blob image on OAF Page?

    Hi,
    Yes I am using same code specified by Kali. My requirement is exact same with it.
    The debugger does not jump to the servlet class from CO.
    By the way the CO and servlets are in the same package.
    This is the page source;
    <img id="imageIT" name="imageIT" src="ReadPerImage?id=4
    {code}
    This is the servlet mapping in web.xml;
    {code}
       <servlet-mapping>
          <servlet-name>ReadPerImage</servlet-name>
          <url-pattern>/readperimage</url-pattern>
       </servlet-mapping>
    {code}
    Thanks.
    Edited by: user8627992 on 23.Şub.2011 04:49                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • MAX: How to display icons (blob) in VB

    Hi!
    I've written a VB application which gets some information from MAX. It works very well, but I was wondering how to display the icons (stored as blob). Who can help me? Thank you in advance!!
    here is a piece of my code:
    Dim maxConf As mxConfiguration
    Dim maxItems As mxItems
    Dim maxItemAttribute As ImxItemAttribute
    Set maxConf = New MXCTRLLib.mxConfiguration
    maxConf.Initialize ("Local")
    Set maxItems = maxConf.EnumItems("CAT=Software,ALL")
    Set maxItemAttribute = maxItems.Item(ItemsListBox.ListIndex).EnumItemAttributes.Item(AttributesListBox.ListIndex)
    Select Case maxItemAttribute.AttributeType
    Case "Blob"
    'here, I want to display the icon and I need your help!
    Case Else
    ListBox1.AddItem (maxItemAttribute.AttributeValue)
    end select

    I will try this when I get back home - travelling at the moment.
    A bit more background....... I have a Function that is called to produce a yearly calendar view of rentals for a home, along with the rental prices - this has already been written using the as_pdf3 package, which can either physically create the report on the server (using utl_file), or it can return the blob direct.
    On the screen, the user can select the years that they wish to see in the report, push a button which will pass the parameters into the above said function, and then launch the "blob" in another window (as the blob is PDF format, it would launch the users PDF reader) - if the user then wants to save the report, they can do (using PDF reader) - this avoids me a) saving and housekeeping a file(s) on the server, b) I don't have to enable utl_file for the schema

  • How to display a horizontal list of images

    Hello everyone,
    I am new to Flash Builder 4 and I am looking to display a horizontal list of images on my Flex Mobile Project (using Burrito Flash Builder). Can anyone recommend me what component that I should use?
    I know the <s:List /> will display a Vertical list of items, but I am not sure what component to display a horizontal list of items.
    Thanks in advance for any help,

    Have you tried using HorizontalList?
    Here is an example:
    http://flex4fun.com/2010/11/30/flex4-horizontallist-example/

  • How to display different parts of an image

    hi,
    I need to display different parts of an image at specific situations.
    for example, a dice. there is only one image which includes different sides of the dice. and I wanna add
    to my panel one side if one comes, two side if two comes... I mean if one comes then we will display
    from 10 px to 80 px width and from 10 px to 80 px height of the dice image.
    is there any way to obtain this in java?
    thanks...

    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.util.Random;
    import javax.swing.*;
    public class ImageClipping extends JPanel {
        BufferedImage image;
        Rectangle clip;
        final int ROWS = 3;
        final int COLS = 3;
        public ImageClipping() {
            // Make an image we can clip.
            Dimension d = getPreferredSize();
            int type = BufferedImage.TYPE_INT_RGB;
            image = new BufferedImage(d.width, d.height, type);
            Graphics2D g2 = image.createGraphics();
            g2.setBackground(getBackground());
            g2.clearRect(0, 0, d.width, d.height);
            Font font = g2.getFont().deriveFont(36f);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("0", frc);
            float sh = lm.getAscent() + lm.getDescent();
            int xInc = d.width/COLS;
            int yInc = d.height/ROWS;
            for(int j = 0; j < ROWS; j++) {
                for(int k = 0; k < COLS; k++) {
                    String s = String.valueOf(j*COLS + k+1);
                    float sw = (float)font.getStringBounds(s, frc).getWidth();
                    float sx = k*xInc + (xInc - sw)/2;
                    float sy = j*yInc + (yInc + sh)/2 - lm.getDescent();
                    g2.setPaint(Color.red);
                    g2.drawString(s, sx, sy);
                    g2.setPaint(Color.blue);
                    g2.drawRect(k*xInc, j*yInc, xInc-1, yInc-1);
            g2.dispose();
            clip = new Rectangle(xInc, yInc);
            // Inspect image.
            ImageIcon icon = new ImageIcon(image);
            JOptionPane.showMessageDialog(null, icon, "", -1);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            Shape origClip = g2.getClip();
            //g2.setPaint(Color.red);
            //g2.draw(clip);
            // Draw clipped image at:
            int x = 100;
            int y = 100;
            // Mark location.
            g2.setPaint(Color.red);
            g2.fill(new Ellipse2D.Double(x-2,y-2,4,4));
            // Position the image.
            g2.translate(x-clip.x, y-clip.y);
            // Clip it and draw.
            g2.setClip(clip);
            g2.drawImage(image,0,0,this);
            // Reverse the changes to the graphics context.
            g2.setClip(origClip);
            g2.translate(clip.x-x, clip.y-y);
        public Dimension getPreferredSize() {
            return new Dimension(400,400);
        public static void main(String[] args) {
            ImageClipping test = new ImageClipping();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test);
            f.pack();
            f.setLocation(50,50);
            f.setVisible(true);
            test.start();
        private void start() {
            Thread thread = new Thread(runner);
            thread.setPriority(Thread.NORM_PRIORITY);
            thread.start();
        private Runnable runner = new Runnable() {
            Random seed = new Random();
            Dimension d = getPreferredSize();
            int xInc = d.width/COLS;
            int yInc = d.height/ROWS;
            public void run() {
                do {
                    try {
                        Thread.sleep(3000);
                    } catch(InterruptedException e) {
                        break;
                    int row = seed.nextInt(ROWS);
                    int col = seed.nextInt(COLS);
                    int x = col*xInc;
                    int y = row*yInc;
                    int n = row*COLS + col+1;
                    System.out.printf("row = %d  col = %d  n = %d%n",
                                       row, col, n);
                    clip.setLocation(x,y);
                    repaint();
                } while(isVisible());
    }

  • How to display a BLOB (Image) in a EBS Report?

    User requested to add a Logo image to a report which is called from E-Business Suite (EBS).
    The image is currently stores in a BLOB column.
    How can I make the image to display on the report?
    Thanks!

    I was trying to use the BLOB and display the image in a report.
    Per your suggestion:
    "Select the column in your query.
    Create an item in the layout editor and set the source to this column.
    Set File Format to Image."
    My question was I dont know how to "set the source to this column" as you described above.
    So, to work around it, I moved the image file phyically to the UNIX file system.
    Then, created an item in the layout editor which required a valid "image file path" the property palette.
    Since, the report was created under windows, it did not validate with UNIX file path.
    That's why i need to perform extra steps to get the file path correct to work in UNIX.
    EDIT:
    I guess when you said "set the source to this column", you mean to map the "Field source" attribute in the property palette to the database column from query.
    But depends on what item you want me to create (I created a "Link File" item) and it does not have the "Field source" attribute available to map to a database column.
    Edited by: user595907 on Sep 21, 2009 9:47 AM
    Edited by: user595907 on Sep 21, 2009 9:54 AM

  • How to display clob/blob in the web layout using Reports9i

    Hi,
    I've created a report that selects both a clob and blob datatype in the query. However, when I run the report using the 'Run Web Layout' tool no data is displayed for these columns. Does the <rw:field> tag support such datatypes ?.
    Regards,
    Chris

    Hi Chris,
    Reports9i supports both BLOB and CLOB in both paper as well as web layout. Pl make sure that in the column properties that you want to display, you have selected the "File Format" correctly (to do this, go to data model > column > property inspector > file format). Eg, you can select "text", "image" etc depending on what you have stored in the column. Also, when you want to display an image in the web layout, you will have to write containsHtml="yes" inside your <re:field> tag.
    Navneet.

  • SOLUTION - How to display a BLOB content in Portal Report

    Courtesy of Kelly Wong:
    1. Every time a record of the file information is inserted into the
    PORTAL30.WWDOC_DOCUMENT table while you inserted a record to the blob
    field in a portal form that you created.
    [The fact that a file uploaded appears in the WWDOC_DOCUMENT table is actually a side-effect of Forms file upload, this may change in a future version. However this example gives a pretty good solution to the problem - Dmitry]
    2. If you describe the PORTAL30.WWDOC_DOCUMENT table, you will find
    that a few of the columns are: NAME, FILENAME, MIME_TYPE, BLOB_CONTENT,
    CREATOR, etc.
    3. I created a pl/sql procedure that takes a NAME parameter.
    The code of the procedure is as follows:
    CREATE OR REPLACE Procedure get_url
    (V_FILENAME IN VARCHAR2)
    IS
    url varchar2(100);
    BEGIN
    url := '/pls/portal30/docs/'&#0124; &#0124;v_filename;
    portal30.wwv_redirect.url(p_url =>url);
    END;
    4. I then created a portal report, select NAME, FILENAME, MIMETYPE,
    CREATOR fields from PORTAL30.WWDOC_DOCUMENT. (remember, no BLOB_CONTENT
    field is selected!) My select statement is:
    SELECT '<A
    HREF="scott.get_url?v_filename='&#0124; &#0124;name&#0124; &#0124;'">'&#0124; &#0124;filename&#0124; &#0124;'</A>' filename,
    name,mime_type,creator
    from portal30.wwdoc_document
    where creator = 'KELLY'
    You can see that I am passing in "NAME" instead of "FILENAME" into the
    get_url procedure because the it needs the "NAME" info to display the
    file.
    Actually, the content in the NAME column is something like:"563.TXT",
    and the content in the FILENAME column is "F15675/IPORTAL_LOCAL.TXT".
    The hyperlink can be either on the NAME or FILENAME field, as long as
    you pass in the content of "NAME" into the procedure.
    And it should be fairly easily to substring the FILENAME to show only
    "IPORTAL_LOCAL.TXT" if the client doesn't like to see the number
    portion.
    That is, when I click on the link, I am able to see my file in a new
    browser window.The only drawback in this scenario is if there is a link
    from your document to a portal component (form/report), it may not link
    to the form/report. If there are links in the document link to other
    document (html, txt, etc.), it will be no problem. It just open the
    document in another browser window.
    Please feel free to give me any comment on this and post it to the forum
    if needed. I just don't want to search for the original questions in
    the forum and attach the reply to it.
    Regards;
    Kelly.

    Is this method working also for portal 3.0.9?
    I can't get it to work.
    Is there a way do put a link to download the content of a blob field inside a report in version 3.0.9 that comes with iAS 1.0.2.2?
    Thank's in advance
    Mauro

  • How to display a blob??

    i have a table with a column as a blob (pic file), is there a way to get the blob to display, without having to use the content area...
    i've tried reports but blobs are not supported...
    thanks

    Saad
    You can build a Form component to insert/upload, query, and open a file as a BLOB and/or leverage the PL/SQL Gateway features within Oracle9iAS. See: http://technet.oracle.com/docs/products/ias/doc_library/ias102/comm.102/a86263/feature.htm#1004906

  • How to display a blob in a new window (without saving as file)

    Hi,
    I have been using the excellent as_pdf3 PLSql utility to create a pdf at run time. The result works great if I save the blob to file, however, I don't want to clutter up the "server", so I would like to send the blob down to the user by opening a new window (pdf reader) and then give the user the option to save where they wish.
    I am running Apex 4.1.1, Oracle 11GXE with Apex Listener under Glassfish opensource on Ubuntu Server 11.2.
    I've hunted left right and centre, and either I've not got the correct combination of words in the search, or the question has never been raised.
    Can anyone give me some pointers and/or code to assist ?

    I will try this when I get back home - travelling at the moment.
    A bit more background....... I have a Function that is called to produce a yearly calendar view of rentals for a home, along with the rental prices - this has already been written using the as_pdf3 package, which can either physically create the report on the server (using utl_file), or it can return the blob direct.
    On the screen, the user can select the years that they wish to see in the report, push a button which will pass the parameters into the above said function, and then launch the "blob" in another window (as the blob is PDF format, it would launch the users PDF reader) - if the user then wants to save the report, they can do (using PDF reader) - this avoids me a) saving and housekeeping a file(s) on the server, b) I don't have to enable utl_file for the schema

  • How to display image in blob field in ResultSet in SiteStudio?

    I am running Site Studio 10gR4. For a custom page, I created a component that basically runs a query. The structure of the underlying data is a combination of Varchar2, Date and a single BLOB field. The blob field either contains a simple jpeg image, or nothing.
    In my Page where I am looping through the data, how do I display the blob as an image?
    Currently the code looks like this:
         <!--$loop SQLRoutes-->
              <tr>
                   <td><!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 0))--></td>
                   <td><!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 1))--></td>
                   <td><!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 2))--></td>
                   <td><!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 3))--></td>
                   <td><!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 4))--></td>
                   <td><!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 5))--></td>
                   <td><!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 6))--></td>
              </tr>
         <!--$endloop-->Field 1 is a blob and fields 5 and 6 are dates.
    So really two questions:
    1. How do I display field1 as an image?
    Example:
    <!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 1))-->doesn't do it. Is there a different function then getValue() that I should be using to get the blob contents?
    2. I want to compare the date fields to todays date, and either change the color or conditionally display the fields. I could do this with basic taglibs from jsp. How do I do this with IDocScript?
    Example:
    <!--$if getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 6)) > dateCurrent-->
      <span class="red"><!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 6))--></span>
    <!--$endif-->Thanks, Ken

    I actually don't know the answer to #1. If I were to guess, there's nothing out-of-the-box to handle blobs, so your best option is to write your own idoc function. Take a look at the How To component if you don't know how.
    For #2, you almost have it right. Insert bold:
    &lt;!--$if <b>parseDate(formatDate(</b>getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 6))<b>)) gt</b> dateCurrent<b>()</b>--&gt;
    &lt;span class="red"&gt;<!--$getValue("SQLRoutes",rsFieldByIndex("SQLRoutes", 6))-->&lt;/span&gt;
    <!--$endif-->

Maybe you are looking for

  • I need to open a file with an associated programm.

    I need to open a file with an associated programm. I'm looking for two solutions: 1. for Linux/Solaris/Unix/... 2. for Windows 95/98/Nt/2000 For Windows I have done this with command line Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandle

  • Generic way to set indent-amount on Transformer?

    Does anyone know if there is a generic way to set the indent-amount on a transformer? I'm guessing the property below is specific to apache transformers. I believe we're using an apache transformer by default, but what if the default changes in the f

  • Problems installing CS5.5 ~ Really need help.. Thank you.

    Operating system = WinXP Trying to install purchased CS5.5 Web Premium on completely clean machine recently reformatted. Installing from files downloaded from Adobe. I did a successful install of this last summer, but this time it's been a real pain.

  • Screen layout is not defined for company code ZVVV

    Hi I am creating CUSTOMER MASTER in XD01 I am getting an error like "Screen layout is not defined for company code ZVVV" Can any one help?

  • Arbitrary JNDI names

    I am trying to deploy a session bean by specifying an arbitrary JNDI name in the file ejb-j2ee-engine.xml as below <?xml version="1.0" encoding="UTF-8"?> <ejb-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoca