How to retrive multiple images from database

Hi,
I have to retrieve multiple images from oracle database and have to display the image in the jsp.
I am passing imageCategoryId from the jsp.This id contain number of image in DB.
I googled the issue and i found some solution.want to know whether what i did is correct and how i have to display the retrieved image in jsp.
Need urgent help.Experts kindly help me.
This is my action file.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.NamingException;
import com.image.dao.ImageDAO;
public class GetImageServlet extends HttpServlet{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
try{
     ImageDAO image = new ImageDAO();
String categoryId = request.getParameter("catgId");
     bytes[] imagebyte = image.getImagesByCategoryId(categoryId);
InputStream is = new FileInputStream(imagebyte);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(imagebyte);
blobIs.close();
catch(IOException e){
e.printStackTrace();
} catch(Exception excep) {
                    excep.printStackTrace();
This is DAO file
public byte[] getImagesByCategoryId(String categoryId) throws Exception
          PreparedStatement statement = null;
          ResultSet resultSet = null;
          StringBuffer queryBuffer = new StringBuffer();
          Blob image = null;
          String imageId = null;
          ArrayList imageIdLIst = new ArrayList();
          try {
               this.connection = connManager.getDataSourceConnection();
               queryBuffer.append("select image from Image_Table where image_category='"+categoryId+"'");
               statement = connection.prepareStatement(queryBuffer.toString());
               resultSet = statement.executeQuery();
               while(resultSet.next()) {
                    image = rs.getBlob(1);
                    long imgLength = image.getBufferSize();
                    byte[] byteImage = new byte[imgLength];
                    byteImage = image.getBytes(1,(int)imgLength);
          } catch(Exception excep) {
               excep.printStackTrace();
          return byteImage;
How to display retrieved image in jsp.
whether action and dao file is correct or what changes i have to do to correct the problem.
P.S : As a Newbie i dont know how to use code tag for this java code.Kindly forgive me.
Regards,
hardlyUsed.

hardlyused wrote:
I have to retrieve multiple images from oracle database and have to display the image in the jsp.There are at least two parts to the problem.
1. Get it from the database.
2. Display it.
Part 1 has nothing to do with part 2.
You must solve 1 before you solve 2.
Finally generically there is no such thing an "image" but rather there is binary data which is represented in such a way that it one of many formats that represent an "image".
Knowing which specific format the "image" is stored in will at a minimum be helpful and could be required.

Similar Messages

  • How to retrieve am image from database

    hi ,
    i hav a requirement that, i hav to store and retrive an image from database(postgresql)and palce it on JLabel.i successfully stored an image into database .while retrieving an image from database im not getting the image .please any one can help me how to retrieve an image and place it in JLabel.
    This the code for inserting an image:
    Class.forName("org.postgresql.Driver");
    Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:port/database", "username", "pwd");
    System.out.println("Connection established");
    String INSERT_PICTURE = "insert into imagedata(imageid,data) values (?, ?)";
    FileInputStream fis = null;
    PreparedStatement ps = null;
    try {
    conn.setAutoCommit(false);
    File file = new File("photo.jpg");
    fis = new FileInputStream(file);
    ps = conn.prepareStatement(INSERT_PICTURE);
    ps.setInt(1, 2);
    ps.setBinaryStream(2, fis, (int) file.length());
    ps.executeUpdate();
    conn.commit();
    catch(Exception ex)
    ex.printStackTrace();
    finally {
    ps.close();
    fis.close();This is the code for retrieve an image :
    Class.forName("org.postgresql.Driver");
    Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:port/database", "username", "pwd");
    byte[] imgbytes = null;
    String INSERT_PICTURE = "select imageid,data from imagedata ";
    Statement stmt=(Statement) conn.createStatement();
    try {
    ResultSet rs=stmt.executeQuery(INSERT_PICTURE);
    while(rs.next())
    System.out.println(rs.getString(1));
    InputStream file=rs.getBinaryStream(2);
    System.out.println("FILE : "+file);
    catch(SQLException a)
    finally {
    stmt.close();please anyone can help meee
    thanks

    You basically save a File to the database, so you can just re-write the data from the file back temporarily and load it into the application using the ImageIO class
    // create necessary connection and statement objects
    // retrieve image column
    ResultSet rs = stmt.executeQuery("SELECT Image FROM dataTable");
    rs.next();
    Blob imageData = rs.getBlob("Image");
    if( imageData != null ) {
        try {
            File tmpFile = new File("tmpImage");
            FileOutputStream fos = new FileOutputStream(tmpFile);
                fos.write( imageData.getBytes(1L, (int)imageData.length()) );
                fos.close();
            tmpFile.deleteOnExit();
            ImageIcon icon = new ImageIcon( ImageIO.read(tmpFile) );   
            JOptionPane.showMessageDialog(null, icon);
        } catch(IOException ioe) {
            ioe.printStackTrace();
            JOptionPane.showMessageDialog(null, "Failed To Load Image Data", "Load Error",
                    JOptionPane.ERROR_MESSAGE);
    }ICE

  • How to display multiple tables from database using netbeans swing gui

    plz reply asap on how to display multiple tables from database using netbeans swing gui into the same project

    Layered Pane with JTables or you can easily to it with a little scripting and HTML.
    plzzzzzzzzzzzzzzzzz, do not use SMS speak when posting.

  • Retrieve multiple images from database to servlet

    Hi there,
    I try to retrieve more than one images from database to Servlet/JSP . However, I get only one images in the result set. Here is my code. Please Help .
    How do I display more than one images ( multiple rows ) from database to Servlet ?.
    When I retrieve, I got 3 rows of binary data, but I don't know how to display it on the Servlet/JSP pages.
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import java.sql.*;
    import com.sybase.jdbcx.*;
    public class RetrievePhoto extends HttpServlet {
    static ResultSet rs;
    static CallableStatement NGSstmt = null;
    static Connection NGScon = null;
    static SybDriver _driver = null;
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws
    ServletException, IOException {
    ServletOutputStream os = res.getOutputStream();
    String driver = ""
    String URL = "";
    String Host = "";
    String UN = ""; //assign your username here
    String PW = ""; //assign your password here
    try {
    Class c = Class.forName( driver );
    _driver = (SybDriver) c.newInstance();
    DriverManager.registerDriver( (SybDriver) _driver );
    NGScon = DriverManager.getConnection( URL + Host, UN, PW );
    } catch ( SQLException e ) {
    os.println( "Unable to load the Sybase JDBC driver. " + e.toString() );
    e.printStackTrace(System.out);
    } catch (java.lang.Exception ex) {
    // Got some other type of exception. Dump it.
    os.println("Exception - java lang " + ex.getMessage() );
    String PID = req.getParameter("PID"); //passing parameters from Servlet
    try {
    String SQLcmd = "{call RET_PHOTO_BY_PID(?)}";
    NGSstmt = NGScon.prepareCall( SQLcmd );
    //execute the query
    synchronized (NGSIDBstmt)
    NGSstmt.setString(1, PID); //passing parameter to store procedure
    rs = NGSstmt.executeQuery();
    byte[] stuff = new byte[1024];
    int bytesRead = 0;
    res.setContentType("image/gif");
    InputStream is = null;
    // Get the first row
    while( rs.next() ) {
    is = rs.getBinaryStream("PHOTO");
    res.setContentLength(is.available());
    for (int i=0;; i++) {
    bytesRead = is.read(stuff);
    os.write(stuff);
    if ( bytesRead == -1 ) break;
    rs.close();
    os.flush();
    os.close(); //close outputstream
    } catch ( SQLException sqle) {
    os.println("Error in SQL2Exception" + sqle.getMessage());

    When I retrieve, I got 3 rows of binary data, but I don't know how to display it on the Servlet/JSP pages.I will pick this bit of your post, because you seemed to have several partly-overlapping questions.
    You are going about this wrong. You need to decide what your HTML will look like before you start writing servlet code. In this case you want to have something like a table, with an image in each row, right? Now what does the HTML for that look like? It's a <table> element, and so on, but what about the images? Well this is HTML, so it can't contain the binary images. It has to contains links to the images, and the browser will download the image from each of those links and put all of the downloads together into the page it displays.
    That means you can't do it all with one servlet. You need a main servlet that generates the HTML, with the <table> element and the links to the images. Probably you need some DB calls here to find out how many images you're going to have, but you don't need to get them in this servlet. You just need to generate a link for each of them.
    Then you need a second servlet that gets an image. It's going to get a single row from the DB and return the binary image you read from that row. Make sure to use "image/jpg" or whatever's appropriate instead of "text/html" in your response's content type here.
    I will leave you to carry on from here. First step is to design the HTML that your main servlet will produce; remember that the links it generates need to carry enough information for the second servlet to be able to find the right image in the DB.
    PC&#178;

  • Retriving an Image From Database

    Hi friends i tried to retrieve an image from database and get some sample code from one website and try to run. But an error will be displayed please help me..... this is the code............
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.io.*;
    import java.sql.*;
    class GetBlob {
    FileOutputStream image;
    Connection con = null;
    PreparedStatement pstmt = null;
    Statement stmt= null;
    ResultSet res = null;
    StringBuffer query=null;
    String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:image";;
    public GetBlob(){
    try{
    Class.forName(driverName);
    con = DriverManager.getConnection(url);
    stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery("SELECT * FROM save_image where id="+"1"+"");
    if (rs.next()) {
    System.out.println(rs.getString(2));
    Blob test=rs.getBlob("image");
    InputStream x=test.getBinaryStream();
    int size=x.available();
    OutputStream out=new FileOutputStream("C:\\anu.jpg");
    byte b[]= new byte[size];
    x.read(b);
    out.write(b);
    catch(Exception e){
    System.out.println("Exception :"+e);
    finally{
    try{
    stmt.close();
    con.close();
    catch(Exception e){
    System.out.println(e);
    public static void main(String args[]) throws IOException{
    GetBlob blob = new GetBlob();
    The error is
    java.lang.UnsupportedOperationException
    please help me...

    Use a real database and a real driver. MS Access and ODBC bridge aren't.

  • How to insert, select image from database

    can any one help me to store and retrive image from mySQL database....
    plz can any one send me code for this ?
    thank you

    First of all, I suggest not to do this!! Creates to much overhead on your database. Especially if you have large images that your going to put in the database.
    Otherwise what you could do is create a BLOB that contains the bytes to your image and insert that into your database.

  • How to display an image from database

    Hi all,
    I've saved an image(jpeg file) as BLOB item in the database through the forms.I need to fetch that particular image from the database and display the image in the report.How can i do that?
    I tried to fetch the column from the database and added a text item and selected the PHOTO column , the properties has changed once i selected the BLOB item.File format I changed to Image , But the width is 4 and I'm not able to change that.
    While executing I'm getting two errors,
    REP : 0069 Internal Error
    REP : 62203 Internal Error reading the image - Unable to render RenderedOp for this operation
    Please help me to solve this issue.
    Thanks in advance...

    Hello,
    Try to revert to the "old" way to render images :
    http://www.oracle.com/webapps/online-help/reports/10.1.2/topics/htmlhelp_rwbuild_hs/rwrefex/envvars/envvar_reports_default_display.htm
    To revert to the dependency on DISPLAY and use screen fonts (old font look up algorithm):
    Set REPORTS_DEFAULT_DISPLAY=NO.
    Remove the screenprinter.ppd entry in the uiscreenprint.txt file.
    Set the DISPLAY variable to the active X-Windows display surface.
    Regards

  • How to get multiple rows from database table?

    hello !
    I need to get multiple rows from a OLEDB database table and display them on a table object.
    I did "Wrap in subfrom" on the table,  set  subform of the table to "flowed", and checked "Repeat row for each data item" of Row1 of the table.
    But I can get only one row on the table object.
    I need your help.
    Thanks

    Hi,
    best practices when deleting multiple rows is to do this on the business service, not the view layer for performance reasons. When you selected the rows to delete and press submit, then in a managed bean you access thetable instance (put a reference to a managed bean from the table "binding" property") and call getSeletedRowKeys. In JDeveloper 11g, ADF Faces returns the RowKeySet as a Set of List, where each list conatins the server side row key (e.g. oracle.jbo.Key) if you use ADF BC. Then you create a List (ArrayList) with this keys in it and call a method exposed on the business service (through a method activity in ADF) and pass the list as an argument. On the server side you then access the View Object that holds the data and find the row to delte by the keys in the list
    Example 134 here: http://blogs.oracle.com/smuenchadf/examples/#134 provides you with the code
    Frank

  • How to save multiple images from jpeg to psd?

    I'm pretty new at this and have tons of vacation photos. Things I've read have left me terrified of leaving my images in jpeg, but I don't know how to save them all to .psd (and is that really the format I want to use?). I tried, and suddenly I'm out of space on my harddrive, so I think I've made copies of copies and have way more saved than I need. Any advice is appreciated - thanks.

    <[email protected]> wrote<br />> ...Things I've read have left me terrified of leaving my images in jpeg...<br /><br />Andrea,<br /><br />If the JPEG files are straight out of your camera, there is no harm in <br />"leaving" them as-is...  they don't degrade from just sitting there.<br /><br />The possible degradation of JPEG files comes from saving as a JPEG - <br />typically after you have done an edit to the image.<br /><br />One good way to approach the issue:  when you open an image for editing, <br />before you do anything, click the menu File > Save As...  and then choose <br />the PSD file type.  This will make a copy for you to work with, which will <br />NOT degrade as you save, re-edit, re-save, etc.  After you're finished <br />working it over, if you need a JPEG copy, use the File > Save As...  and <br />select JPEG to make an edited copy in the smaller file format.  (File > Save <br />For Web is also useful for this - it allows you to set your quality and size <br />parameters on-the-fly as you save)<br /><br />HTH,<br /><br />Byron

  • How to email multiple images from Aperture?

    When I click the email button, only the primary select is sent to mail. How can I email several images at once?
    Thanks for your help.
    Nicolas

    You know you can access your Aperture Library in the New Message Window in Mail on 10.5?
    Uploaded with plasq's Skitch!
    You can then drag multiple pics over to the Window.

  • How can we load images from database to macromedia flash?

    Dear All,
    Actually I'm creating a intractive CD with images(Catalogue)
    loaded in access db. I don't want every user to install the program
    into his pc. When he/she inserts cd it should play and display
    images by category wise (9 pictures at one time). is there flash or
    vb code to acheive this in flash or any flash sample projects
    highly appreciated.
    Thanks a lot

    Hello
    You should look into the option of Retraction from BW to ECC. You may find a lot of docs on the same. Refer the below link for the same
    https://scn.sap.com/thread/1008067
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/90cd1106-21b4-2d10-0695-9b1e076191eb?QuickLink=index&overridelayout=true
    Regards
    Gajesh

  • How to load a image from database to image item in oracle 10 g form

    I have stored some images in the Database Table with BLOB datatype. Now I need to load that image in the non database image item. Please advise. Thanks.

    You need to have a print server installed to generate the pdf. Either use BI Publisher and it's desktop development tool or use FOP/Cocoon.. Adding an image with them is a little more involved..
    Thank you,
    Tony Miller
    Webster, TX
    While it is true that technology waits for no man; stupidity will always stop to take on new passengers.

  • Retrieving image from database in form 6i

    hello all
    i'm working on form 6i...
    i have uploded images into the database of customers in my application using READ_IMAGE_FILE.. IT IS FINE...
    But when i am trying retrieves records into the form.... i'm getting all the data except image... Image field is showing empty..
    How can i get image from database to form
    can u plz help me.....
    thanks

    What data type you used for storing image in database. If it is long raw, then you can place an image item within your data block on form and associate it with the column name. This should populate the image by itself.
    Below para is from Forms Help.
    Image items can be populated in the following ways:
    +1. a fetch from a LONG RAW database column+
    An image item in a data block is populated automatically when the end user or the application executes a query in the block.  When a fetched image is modified or replaced, Form Builder marks that record as Changed, and the next commit operation saves the new image to the corresponding LONG RAW column in the database.
    Note:  You cannot write a SELECT statement to select a LONG RAW value INTO an image item.
    +2. executing the READ_IMAGE_FILE built-in to read an image from the file system+
    +(To dynamically write an image from an image item out to a file, use the built-in procedure WRITE_IMAGE_FILE.)+

  • How to save an image to database and retreive from it.

    how to save an image retreived from an bytearray to database and retreive back the image from database....pls specify the steps and the query.

    You can use the JDBC API for database connectivity and you can use SQL to query the database.
    JDBC tutorial: http://www.google.com/search?q=jdbc+tutorial+site:sun.com
    SQL tutorial: http://www.google.com/search?q=sql+tutorial+site:w3schools.com

  • How do I import multiple images (from Aperture) to multiple pages in Pages?

    I can select and drag multiple images from Aperture to Pages, but they all are inserted on the same page. If I have 100 images, can I force Pages to insert one image on each of 100 pages?
    Thanks,
    Rick

    Burn for what purpose? To share with others?
    Export the photos to a folder on the Desktop. Burn that with the Finder. Result: a folder of images that any computer can read.
    Using iPhoto's Burn command creates an iPhoto Library on the disk and is suitable only for others also using the same version of iPhoto.
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.
    Note that rewriteable disks do not necessarily mean that you can append files to them, and require special burning software to do so.
    Regards
    TD

Maybe you are looking for

  • Want to clean and reinstall my early 2009 IMAC, but have Snow Leopard and no discs

    Have an Early 2009 IMAC.  My daughter (14, and an indiscriminate clicker of "OK" buttons on pop ups to get rid of them) has been using it for a year, and is it is now running very slowly, locking up, etc.  I am not particularly computer savvy, but wo

  • ITunes 7.4 won't recognize my library files

    I have all my music on an external hard drive and just changed from set playlists to smart playlists. I upgraded to 7.4 tonight and 1) It wouldn't import my library.XML file 2) Couldn't find my iTunes folder on the external hard drive 3) Erased all m

  • Performance question for date column

    Hi All, I have a select query which joins two tables with more than 20 million records each based on a where condition of year = 2006. Would creating an function based index on the date column help improve the performance. Please suggest any other al

  • How can I change the print quality on a HP 6700 to draft (lowest quality) on a Mac OS X 10.9.3?

    Hi, I've tried many places to try to find where I can change the print quality (HP 6700).  I don't want it to use so much ink, so want to put it at the lowest quality.  I tried using the settings icon and the arrows on the front of the printer, and o

  • "Mail" can't remember password for cloud mail

    In preparation for the iCloud move on July 1, 2012, I updated to latest version of OS X 10.7, and had everything working. As of July 1 I get: Enter Password for Account "MobileMe" The iCloud IMAP server "p99-imap.mail.me.com" rejected the password fo