Retrieval of image (Blob) from database - doesn't always work in JSP - Why?

In my JSP pages, when an image needs to be retrieved, I direct <img src> to a servlet that handles image processing.
As an example, if I have 30 products that need to be shown on 1 webpage, there will be 30, dynamically generated, <img src="go.imageServlet?id=a1"> tags/statements. The servlet, when called, will make a connection to the database, run a query for the image requested (fetched as type Blob), image displays in <img src> area of JSP page, and finally the ResultSet, Statement, and Connection object(s) are closed.
I tested this out, and unfortunately, to my surprise, and disappointment, a few images did not display on the page. Though the images are in the database table. I'm a little lost as to why this problem is occurring.
Can someone please shed some light on this for me?

evnafets wrote:
If you request just one image, does that image come back broken, or is it different images that are 'broken' each time?On a page of almost 30 image requests (thumbnail size), it varies, but typically, 1-3 images are 'broken' each time. And they are not always the same images. Very strange.
There may potentially be thread concurrency errors depending upon how you have written your servlet - ie one request for an image interfering with another because they use the same variable.
To make it threadsafe, in your servlet make sure that you only use variables local to the doGet/doPost method, and not any class attributes.In my JSP page that makes the requests for these images, a String array generates the <img src> tags on the page, as a very basic example :
<%  for(int i=0; i<products.length; i++) {
%>
      <img src="go.imageP?imageNumber=<%=products[[0]%>">
<% }//for %>
Sorry for not posting code snippets from my servlet in my first post of this topic....
Here is my servlet snippet -     public class ImageProcessingServlet extends HttpServlet {
          public Connection conn = null;
          public ResultSet rs = null;
          public Statement stmt = null;
          public PreparedStatement pstmt = null;          
          public PrintWriter out = null;     
          public String siteNameReference = "";
          int maxFullSizeImageWidth = 600;          
          int maxSizeImageWidth = 300;
          int maxSizeThumbWidth = 140;
          int maxImageFields = 4;
          String errorMessage = "";               
          public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
               doPost(req,res);
          public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
          try {                       
     HttpSession session = req.getSession();
     siteNameReference = req.getParameter("snr");
     String process = req.getParameter("process");
     if(process == null) process = "";
               Context ctx = new InitialContext();
          if(ctx == null )
throw new Exception("Boom - No Context");
          DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/imageDB");
     conn = ds.getConnection();
     stmt = conn.createStatement();      
          rs = stmt.executeQuery("Select "+imageNumber+" from images");
          rs.next();
          Blob blobImage = rs.getBlob(1);               
          getImage(blobImage,"thumb",res);
          if(rs != null) { rs.close(); }
          rs = null;
     if(stmt != null) { stmt.close(); }
     stmt = null;
     if(pstmt != null) { pstmt.close(); }
     pstmt = null;
     conn.close();
     conn = null;          
          }//try
     catch (Exception e) { }
     finally {
               if (rs != null) {
               try { rs.close(); } catch (SQLException e) { ; }
               rs = null;
               if (stmt != null) {
               try { stmt.close(); } catch (SQLException e) { ; }
               stmt = null;
               if (pstmt != null) {
               try { pstmt.close(); } catch (SQLException e) { ; }
               pstmt = null;
               if (conn != null) {
               try { conn.close(); } catch (SQLException e) { ; }
               conn = null;
          }//finally
     }//post          
          public void getImage(Blob blobImage, String imageType, HttpServletResponse res) {
               try {                                              
                    //imageType will = Super = 600
                    // = Large = 300
                    //               = Thumb = 150
                    res.reset();
                    res.setContentType("image/jpeg");
                    BufferedInputStream bis = new BufferedInputStream(blobImage.getBinaryStream());                    
                    BufferedOutputStream bos = new BufferedOutputStream(res.getOutputStream());                                                            
                    if(imageType.equals("super")) {
                    byte[] imageBytes = new byte[(int)blobImage.length()]; //picture size           
     int length;
     while((length = bis.read(imageBytes)) > 0) {
bos.write(imageBytes, 0, length);
     bos.flush();     
               res.flushBuffer();
                    } else
                    if(imageType.equals("large")) {
                         resize(bis,bos,maxSizeImageWidth);
                         bos.flush();
                         res.flushBuffer();
                    } else
                    if(imageType.equals("thumb")) {
                         resize(bis,bos,maxSizeThumbWidth);
                         bos.flush();
                         res.flushBuffer();                         
                    }//if
                    //close streams
                    bis.close();
                    bos.close();
               }//try
               catch(Exception e) {}
          }//end          
     public void resize(BufferedInputStream bis, BufferedOutputStream bos, int maxImageWidth) {
          try {                            
          BufferedImage bufimg = ImageIO.read(bis);                                         
          //size of image
          int img_width = bufimg.getWidth();
          int img_height = bufimg.getHeight();               
          double scale = (double)maxImageWidth/(double)img_width;                    
          Image sized = getScaledInstanceAWT(bufimg, scale, Image.SCALE_SMOOTH);
          //convert image to BufferedImage
          BufferedImage resized = toBufferedImage(sized, BufferedImage.TYPE_INT_RGB);                                                                                
                    ImageIO.write(resized,"jpeg",bos);                                                                           
     }//try
     catch(Exception e){}
}//end
Edited by: webnotick on Apr 13, 2010 12:24 PM
--added a method to the code snippet --                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Mounting server/NAS by name doesn't always work...why?

    Hello,
    I'm experiencing an odd issue. I have a NAS on my network (D-Link DNS-323) to which I've assigned a name using its own set up. It then shows up in my finder and I usually can mount it just by clicking on it (or actually, I have an automated action to do that when my location is home). However, occasionally it will fail to mount. It will tell me something on the lines of "the server DNS323 cannot be mounted or is unavailable" or something like that. Even trying the "connect to server" command with the smb:// doesn't work and Finder will show a "Connection Failed" response. What's weird is that, when that happens, I can do a connect to server command and write in the device's IP address and it connects no problem. The only change I've made recently to my network is I've replaced an old D-Link router with an Airport Extreme. Not sure if that is a variable. Obviously I can connect with the NAS name sometimes. I can't for the life of me see a pattern. The only one data point is that the connection invariably fails when I go from wi-fi to ethernet or vice-versa. All other times I'm not sure. Any suggestions?

    Sorry, I've solved the problem myself: the albums that wouldn't sort properly were ones in which the artist name was marked in "Album Artist" field as well as the "Artist" field. So I put the "surname, firstname" in the "Sort Album Artist" field as well as the "Sort Artist" field, and they sorted properly!

  • Desktop not loading, I have to keep restarting computer and it doesn't always work!! Why???

    everytime I turn on my computer it loads the basic desktop (factory settings one) with non of my icons or image.
    Sometimes if I restart my computer it loads correctly and other times I have to keep restarting my computer.
    This is extremely annoying can anyone help to fix this issue.
    It is happening on both mine and my spouses computer and both computers are less than 12 months old!
    thanks.

    Hello m ember87un
    What operating system are you running and what model of HP computer do you have? Based on your description it sounds like your user profiles may be corrupt or the computers are experiencing other problems. According to a Knowledge Base (KB) article from Microsoft this can also be caused by antivirus software scanning your computer what you try to log in. See the link to the KB below for troubleshooting steps if you are running Windows Vista or Windows 7.
    As you can see in the symptoms Windows is loading a temporary profile for you. Do you receive any messages similar to "The user profile service failed the logon. User profile cannot be loaded."? Let me know what happens.
    Don't forgot to say thanks by giving "Kudos" to those that help solve your problems.
    When a solution is found please mark the post that solves your issue.

  • I get error message each time I try to retrieve image (BLOB) from Oracle

    Can anyone help me?
    I am working with Servlet and JDBC with Oracle database. I can insert an image (GIF file) in a Oracle
    table in a BLOB field. But everytime I want to retrieve it
    I got an error "AbstractMethodError". My retrieve program (only the main part) is as below:
    String dbURL="jdbc:oracle:thin:@200.200.100.2:1521:tvm";
    String db_username="PROJ1"; String db_password="PROJ1";
    try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    }catch(ClassNotFoundException e1){ }
    try{
    Connection c=DriverManager.getConnection(dbURL,db_username,db_password);
    // Retrieving image file from database
    RandomAccessFile raf=new RandomAccessFile("//Davison/jakarta/webapps/examples/images/a10.gif","rw");
    PreparedStatement pstmt2=c.prepareStatement("Select fname,photo From testtable1 where fname=?");
    pstmt2.setString(1,"rere100");
    ResultSet rs=pstmt2.executeQuery();
    while(rs.next()){
    Blob blobImage=rs.getBlob("photo");
    int length=(int)blobImage.length();
    byte[] blobArray=blobImage.getBytes1,length);
    raf.write(blobArray);
    raf.close();
    Please help me soon, my email is: [email protected]
    Bye , Rea

    Probably a bit late, but I just got the same problem.
    Oracle seems to instantiate a class which is not fully defined-
    oracle.sql.BLOB. This class has abstract methods, and is therefore
    an abstract class.
    In short, Oracle are stupid fools. How they managed to instantiate
    an abstract class in the first place should be of concern to the
    Java gurus, however. Native code in the OCI driver perhaps?
    If you still need help, you could try uning the Thin driver- or
    a database with a JDBC driver which actually meets the spec. There
    are third party Oracle drivers which might fit the bill- they
    usually cost money, however.

  • Jasper report on HTML when one image loaded from database and for the other

    How to generate jasper report on HTML when one image loaded from database and for the other we give a image path
    My code
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
              exporter = new JRHtmlExporter();
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
              exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
              exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, strImageInputDirectory);
         exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME, strImageOutputPath == null ? "." : strImageOutputPath);
         exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
         exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
         exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
              exporter.exportReport();
              byte[] bdata = ((ByteArrayOutputStream) baos).toByteArray();
    Can any one help pls
    Message was edited by:
    ameet.au

    hey sorry for posting it in this forum.
    but do u have sample code for making it work.. since i am able to do it on PDF format(image from Database and another stored in the webserver) using
    byte image[] =(byte[]) outData.get("image");
                        ByteArrayInputStream img = new ByteArrayInputStream(image);
                        hmimg.put("P_PARAMV3", img);
    print = JasperFillManager.fillReport(reportFileName, hmimg, jrxmlds);
    bdata= JasperExportManager.exportReportToPdf(print);

  • Getting image path from database( Remote server)  & display in jsp page

    hai frnds,
    i have one doudt regarding in my web application Development
    . I want to Getting image path from database( **Remote server**) & display in jsp page here iam forwarding my control through Servlets
    how this will passiable
    Thanks in Advance
    SonyKamesh
    [email protected]

    hai
    I think ur doubt will be...
    1) Getting a Image From Remote Server( & U stored a only path name in Data Base)
    2) Image r stroed in saparate Drive( Not in Webroot-- where u Created domine )
    Please Any Help Will be Appriciated
    [email protected]
    Edited by: Sonykamesha on Dec 18, 2007 11:02 PM

  • Arabic Characters data is retrieved ??? from database

    Hello
    on entering Arabic Characters data is retrieved ??? from database 10G 2
    any suggestions pls
    my pc lang is Arabic default
    my nls_lang is ARABIC_SAUDI ARABIA.AR8MSWIN1256
    both for : KEY_DevSuiteHome1
    and the : KEY_OraDb10g_home1
    Regards,
    Abdetu

    If this is a recent installation and the non-Arabic data in the database isn't critical, the simplest solution would be to delete the existing database on your colleague's machine and to create a new one. Assuming you're using the DBCA to create the database, make sure when going through the installation this time that the database character set supports Arabic data (i.e. a database character set of Windows-1256 or UTF-8).
    And if these databases are intended to be separate development databases for the same project, I would suggest spending some time working on developing a process to ensure that each developer's local instance is configured identically and that these configurations match the production configuration. It would be unfortunate, for example, if you were developing on a Windows-1256 database and the production database turned out to have a different character set. The simplest (though not necessarily most elegant) solution would probably to create a template using the DBCA and to use that template on each developer's machine rather than having people individually click through the installer.
    Justin

  • Error retrieving REN server URL from database

    Getting the following error in MCFLOG1 and USQSRV1 log files. Checked all published REN solution guide, nothing really worked. REN server seems to be working though. Coming from loadbalancerURL.peoplesoft.com it pings and REN features work. Ren is set up using machine names though. If logging in directly to machinename.peoplesoft.com REN ping fails with Forbidden error, but that could be a caching issue. I am worried about the log files below and the app. server performance deterioration which may or may not be related.
    We have machine1 with web/app (REN is configured there) and machine two with web/app on it. Also, there is an F5 load balancer in front of them. Any thoughts?
    PSMCFLOG1.5324 (0) [07/09/12 00:18:16](1) (PSMCFLOG1): Error retrieving REN server URL from database
    PSMCFLOG1.5324 (0) [07/09/12 00:19:16](1) (PSMCFLOG1): Error retrieving REN server URL from database
    PSMCFLOG1.5324 (0) [07/09/12 00:20:16](1) (PSMCFLOG1): Error retrieving REN server URL from database
    PSMCFLOG1.5324 (0) [07/09/12 00:21:16](1) (PSMCFLOG1): Error retrieving REN server URL from database
    PSMCFLOG1.5324 (0) [07/09/12 00:22:16](1) (PSMCFLOG1): Error retrieving REN server URL from database

    I restarted the services and the error stopped.
    Thanks
    Ramya

  • How to retrieve the image back from the running CSS

    how to retrieve the image back from the running CSS

    Gilles,
    Thank for your response.
    But the version we use is sg0740107s and can not download from the Cisco Web site any more.
    Does cisco have a archive site for all the image so that the user can download it?
    sctorcss1# sh ver
    Version: sg0740107s (07.40.1.07s)
    Flash (Locked): 07.20.2.06
    Flash (Operational): 07.40.1.03
    Type: PRIMARY
    Licensed Cmd Set(s): Standard Feature Set

  • "Put" command doesn't always work

    Hi,
    I'm looking for a confirmation that the put command doesn't
    always work in DW8.
    I don't use check in/out, so I have started to rely on the
    Put command, rather than going in to Windows Explorer to copy and
    paste web page changes from Local to Remote (via LAN). But even
    when I know there are differences between the local and remote
    file, the Put command will often report that the Local file was not
    moved to the Remote location because DW thinks the Remote file is
    the same as the Local. I get a log message like this:
    "the file" - same - not transferred
    But, I can confirm the local is newer than the remote by
    manually copying and pasting. I can see a different timestamp and
    file size in Windows Explorer.
    Is this command "broken" in DW8?
    Thanx,
    Chris

    > I'm looking for a confirmation that the put command
    doesn't always work in
    > DW8.
    You won't get it from me. I have never had it fail since DW2.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "ChrisRi" <[email protected]> wrote in
    message
    news:egg99f$2s3$[email protected]..
    > Hi,
    >
    > I'm looking for a confirmation that the put command
    doesn't always work in
    > DW8.
    >
    > I don't use check in/out, so I have started to rely on
    the Put command,
    > rather
    > than going in to Windows Explorer to copy and paste web
    page changes from
    > Local
    > to Remote (via LAN). But even when I know there are
    differences between
    > the
    > local and remote file, the Put command will often report
    that the Local
    > file
    > was not moved to the Remote location because DW thinks
    the Remote file is
    > the
    > same as the Local. I get a log message like this:
    >
    > "the file" - same - not transferred
    >
    > But, I can confirm the local is newer than the remote by
    manually copying
    > and
    > pasting. I can see a different timestamp and file size
    in Windows
    > Explorer.
    >
    > Is this command "broken" in DW8?
    >
    > Thanx,
    >
    > Chris
    >
    >

  • ITunes 10.4.1 Problem with Key Command Go to Current Song - Doesn't always work

    Since updating to iTunes 10.4.1, I've noticed that the key command, command + L doesn't always work to display the current song.

    I have this problem in iTunes 10.7 (21). The "Go to Current Song" option exists in the Controls menu, but even when audio is playing it is disabled.

  • Why won't Firefox always minimize/resize? Using F11 is a patchy solution that doesn't always work

    Firefox won't always minimize or resize. The upper right hand corner just pulsates. Looking through forums, I found that using f11 can help, but it doesn't always work. Often I have to reboot.
    == This happened ==
    Not sure how often
    == A year ago, maybe

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • [svn:osmf:] 18047: Fix FM-1076: Reconnect timeout doesn't always work.

    Revision: 18047
    Revision: 18047
    Author:   [email protected]
    Date:     2010-10-06 16:29:01 -0700 (Wed, 06 Oct 2010)
    Log Message:
    Fix FM-1076: Reconnect timeout doesn't always work.
    Ticket Links:
        http://bugs.adobe.com/jira/browse/FM-1076
    Modified Paths:
        osmf/trunk/framework/OSMF/org/osmf/net/NetLoader.as

    "Is it intended to cope with NetConnection.Connect.IdleTimeOut of FMS disconnecting clients after some time of inactivity?"
    The answer is no. Stream reconnect is all about trying to reconnect in the event of a dropped network connection. For the IdleTimeOut scenario, listen for the MediaErrorEvent.MEDIA_ERROR event on the MediaPlayer and check for an error of MediaErrorCodes.NETCONNECTION_TIMEOUT. You can handle that however you wish in your player.
    - charles

  • My iPhone 4 home button doesn't always work. sometimes its just not responsive. other times, it works great. what's the problem, and how do I get it fixed? my iphone  is 2 days old

    my iPhone 4 home button doesn't always work. sometimes its just not responsive. other times, it works great. what's the problem, and how do I get it fixed? my iphone is 2 days old

    Hi there,
    I would recommend taking a look at the troubleshooting steps found in the article below.
    iPhone: Hardware troubleshooting
    http://support.apple.com/kb/TS2802
    -Griff W.

  • My iphone 5 power button doesn't always work.  I have heard this is an issue and Apple will replace it if under warranty, but I have a broken screen.  Will they still replace it?

    My iphone 5 power button doesn't always work.  I have heard this is an issue and Apple will replace it if under warranty, but I have a broken screen.  Will they still replace it?

    It is unlikely but you can atleast try they might set it up for free but expect an email about paying 269 for physical damage

Maybe you are looking for

  • HR ABAP report

    Hello, I am writing a bespoke HR ABAP report. I am using logical database PNP for this. I also need to include the Scale Proficiency Text in my report. I have had a look at the SAP standard Qualifications Overview report and I can see that this uses

  • Include current file location of document in InDesign

    Hi There, is it possible to include the current location of my file in my InDesign-document like it is in MS Word? Please don't ask me why I need that, I also find it stupid but it is a requirement a project work... I would be glad to read your answe

  • How to control which AppServer is used for a process?

    Hello experts! We have the problem that we have 3 Servers from which are 2 running at 99% and one has nearly no processes running. Is it possible to control on which ApplicationServer a process is starting? I know, there is a possibility for process

  • Stopping external swf's with no timeline

    Hey! I just released my portfolio at http://www.hyperactive.se/ which consists of a lot of externally loaded swf's (progressive banners). These swf's contains no timeline really, just one keyframe with an imported FLV. I don't have the source files s

  • WSDLException: faultCode=INVALID_WSDL: Error reading import from oramds

    Hi, We are currently facing a strange problem. We have two composites that needs to be deployed on to the 11g SOA server. composite A and composite B. A is a dependent composite of composite B and we are referring the WSDL of composite B in composite