Getting image stored in database !!

Hey !!
I'm really trying to solve so much problems i'm having with javafx !!
So, like the title may suggest, i'm having problems as to get image from the database !!
Everything seems fine but it tells me that there is "Exception while runing Application"
here is the code !!
@James D, i will come back bugging yu again to see how to use the stored images and display them inside the combobox and to render them ^^
I haven't well understand how well as to use the enum struc in which yu declared the composed <Image,String> type ^^
import java.awt.image.BufferedImage;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javax.swing.JOptionPane;
* @author Minedun6
public class DynamicCustomComboBox extends Application {
    Connection c = connection.ConnecrDb();
   PreparedStatement pst = null;
   ResultSet rs = null;
   ComboBox box1;
   ImageView view;
    public void start(Stage primaryStage) {
        box1 = new ComboBox();
        box1.setPrefSize(100, 25);
        box1.setOnShowing(new EventHandler() {
            public void handle(Event t) {
                try {
            String sql = "select libelle_constr,img_constructeur from constructeurs where libelle_constr='Citroen';";
            pst = c.prepareStatement(sql);
            rs = pst.executeQuery();
               InputStream input = new ByteArrayInputStream(rs.getBytes("img_constructeur"));
               Image imge = new Image(input);
        } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
        StackPane root = new StackPane();
        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("Hello World!");
    public static void main(String[] args) {

In any real application, it's a mistake to mix your presentation (user interface) code with your persistance (database access) code.
Why? You want maintainability, flexibility, and testability.
Suppose you want to change the structure of your database. E.g. the database admin (which may be you, or someone else) determines that the database design you have is inefficient and needs to be changed. If your database code is scattered over the whole application, mixed in among your user interface code, tracking down what needs to be changed will be a nightmare. If all your database code is in a single class, or perhaps a set of classes in a single package, then the updates are localized and much easier to manage. Furthermore, you can build the new database access code on its own, test it out, and then when you are sure it works just switch your user interface code to use the new persistance layer instead of the old one. The same applies if you decide you're going to use a completely different technology to store the data; perhaps you want to use something like Hibernate instead of plain JDBC, or maybe you decide you want to make the data accessibile via a web service.
What if you (or, more likely, your manager) decides they're going to change to a new user interface technology. Maybe they decide to switch to a web application (i.e. HTML-based) instead of a desktop application. You obviously need to rewrite the user interface code, but you should be able to keep all the database access code you've written. If your database access code is all jumbled up with the user interface code you're replacing, it's going to be way harder to reuse that code. If the two are separated out, you just build a new user interface in whatever new technology you're using, and access the same class(es) you used for your database access without touching them.
This whole thread is actually a demo of how testability is much harder if you don't properly separate your code. You posted "getting image stored in database", thinking that was your problem. It wasn't; your problem was actually an error in the way you'd set up your JavaFX code. Because the two were completely mixed together, it was hard to know where the error was. The error you had was actually a really simple one; it would have been much easier to see if you had simpler, properly separated code; but because you didn't organize your code like that it took you days to figure out the problem. This was only a couple of dozen lines of code; imagine how this looks in a real application with hundreds or thousands of classes.
The point is that decisions about how to access your data (standalone database, web service, or EJB?; plain JDBC, JPA, Hibernate, etc?) , and decisions about the presentation technology (desktop or web? JavaFX or Swing?, or Servlets/JSPs, JSF, Swing MVC, or any of a huge number of frameworks) are completely independent. You should be in a position to change those decisions - to redesign aspects of the application - with the least amount of effort possible. Failing to properly design things will make this much harder, or likely completely impossible.
These are real concerns that affect every application that goes into production.
Even if you're just making a small application, it will benefit you to set things up correctly from the outset.

Similar Messages

  • Displaying Images stored in Database

    Hi, all i am having images stored in Databases as BLOB.
    how i can display that in flex application. suppose i am having the ArrayList of Employees in which employee object also have a field of called empImage, how i can display this data in flex.
    i am using BlazeDS.
    Amar Deep Singh

    This will give you the idea of getting the image from you array list. zontallist-control/
    Please rate my answer. Tks

  • 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
    [email protected]

    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

  • Showing Image Stored In DataBase

    Hello Friends,
    I have images stored in MySQL database. In a blob field. In a desktop application i have used
    blob b=rs.getBlob("Picture");
    byte[] buf=b.getBytes((long)1,(int)b.length());
    ImageIcon imgIcon= new ImageIcon(buf);
    Image img=imgIcon.getImage();
    Graphics g=image.getGraphics();
    the thing worked fine. But now i have to show images over web. I am not able to uderstand that how to show images. As i m unable to get Graphics from any of the component.
    Help Me,
    Its urgent,
    thanking u all
    Abhilash Jain

    The common method to include binary information (image, PDF, document, etc) is to Base64 encode the file and store the resulting character string in the XML. It would be up to the receiving system to handle the encoded information in the XML.

  • Pdf printing of an image stored in database?

    I am using pdf printing option, but stuck in a case where I need to retrieve a image from the database table stored as a blob content.
    Is it possible to create a report review of this sort?
    Is this even possible?

    Yes, absolutely.
    Check out this blog post by Marc Sewtz on how to do it -
    Hope this helps,
    Author of Pro Application Express:
    REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone!

  • How to get images dynamically from database without file paths in the table field

    I have a MS-Access database. I am working with ASP.NET. In the database there is product table in which I have "CodeNo" as a field which is a text field, and the product codes like "SM-R-2035". I also have another field "Image" which is also a text field and which have a file path in it corresponding to the particular product Image (e.g. Images\Products\SM-R-2035.jpg). So far every thing is ok. I have to update this site very frequently and lots of images are added each and every time. Its a tedious work to type the paths and file name every time and it also take a lot of time.
    What I am asking is : Is it possible to get images from a specific folder at runtime which is referenced by the "code no" itself and not the file path from the database. (Say at run time the "code no" is referenced from the database and the corresponding image is loaded dynamically from the specified folder). In other word I want to avoid the tedious work of typing.
    Can any one help with this issue. Any other simple suggestions are welcome.

    All you need to do is simple concatenation to obtain the path for the image file.  You didn't mention whether you are using VB.Net, C# or some other language to do your coding.
    If the code in your database is SM-R-2035, the file name is SM-R-2035.jpg and the path to the images foilder is Images\Products\SM-R-2035.jpg, Conceptually here is what you need to do:
    dim code_var
    dim path_var
    code_var = the code you obtain from your relevant field in the database
    path_var = "Images\Products\" & code_var & ".jpg"
    Now path_var is what you would call to obtain the image from your images folder.

  • Serving webpage with image stored in database

    This may look long, but it's easy to understand--I'm just trying to give all the details you might want: In our servlet/JSP site, a user can generate a report that may or may not contain images. The servlet just sends the user to a regular HTML page. The HTML file and images it may have are stored in directories on the Tomcat server. But now we have a problem...
    We're moving to 2 standalone Tomcat machines with a load balancer in front, and so now we want to move any of this stuff that was stored on the webserver into the database. If the HTML text for the report has not yet been generated for that day, I can see my web app going to the database to pull out that HTML, and if there are any images, it could pull those out of the database, but does it get those to the user's web browser?
    Currently, when this report loads in the browser, we do a sendRedirect to the file, and the URL displays the full path to the file (and in the HTML code, there is of course a relative link to the image file). But now, these are supposed to be pulled out of the database...are we going to have to pull them out of the database and then write them out to file on the webserver (since they might not exist on that webserver), or is there some other/better way to display them to the user?

    You can create an Image Servlet that you use to stream the image streight from the db to the page. The URLs that you use in the HTML pages would point to this Servlet with a parameter identifying the image (or you could map the Servlet to *.gif for example). The servlet then sets the content type to the appropriate image format, retrieves the image from the DB as a Stream and copies it byte for byte to the response output stream.
    If you search the forums you will probably find an example of how to do this.

  • How to access images stored in database using forms

    i have created a table which stores images in bfile type
    i would like to access the images along with other data
    stored in forms.iam not able to get the image using select statement.could anyone tell me the format using which i would be able to access the image.

    in my impression, Oracle's samples store the BFILE images off line though if I did not remember wrong.
    If you can create a form type form using form wizard based on that image table, then you may execute query to view the image. But SELECT ... INTO will not work for LOBs on form.
    If off line in file system, you may try to READ_IMAGE_FILE().

  • Images stored in database

    Can XML Publisher create a report that contains an image that is retrieved from the database in an intermedia type column, or must the image reside on the hard drive?

    This will give you the idea of getting the image from you array list. zontallist-control/
    Please rate my answer. Tks

  • Showing image stored in database to XML file

    I have an employee portal from where i can take a report of the employee profile .All the details of the employees are in the table.I am storing the image of the employee as BLOB in the table.
    How will i show the image file in my XML file.
    Thanks in advance.

    The common method to include binary information (image, PDF, document, etc) is to Base64 encode the file and store the resulting character string in the XML. It would be up to the receiving system to handle the encoded information in the XML.

  • How to fetch images stored in database  to reports

    i have stored images in bfile type.i need to access the image.pls do inform me urgently.

    Follow the steps to access images using Reports.
    1. create the sql query in datamodel editor.
    2. Open property inspector for Bfile column
    3. Set file format property to Image.
    4. Goto Report's layout editor
    5. Create field and required frames, set field's source to BFILE column name.
    6. Now run the report
    Oracle Reports Team.

  • Getting images stored inside aknown folder..

    I have aprogram that generate apictures and save them at known path.say " C:/images", then each image is assignes a random number in an accending way.
    Now i want away to get the name of the images inside the folder at the path " C:/images" by java code..
    any one can help me??!!!
    please help me fast..

    i will not offence u ,AndrewThompson64 as u do with me but i want to tell u that u must be more polite when giving ur opinion or ur advice..
    Please stop saying that.u can't order any one to stop asking for knowledge i the way he can ask on it ....
    - it is a waste of bandwidthwho say that asking for knowledge is a waste of bandwidth??!!!!!!
    Sun cimmunity forums is found here to help pepole for dowing there work.. even if the subject is not on his sutable place u can say this more politely..
    - it implies you think your question is more importantt han those of
    other people - it is not more important,to anyone but you..of course it is important for me so i ask it....This also not implies that it is more important than any other question..u can help any one other than me if u want and also any one can help me, why u restrect the answering only from u..
    I want to say also that i put the question here because it is supplement to question i post it previous for converting images to video( multimedia issuese )but i face a problem on developing that example so i post the question here to say if the problem face any one who use that question but when i post the question my error was is to say this thing to clarify my intend..
    thanks Andrew, for justifying for me and i want to say i want see that my words are ander the edge as u say, but i thanks u for giving me the advice more politly..and i will accept it from..

  • How to get images from sybase database

    i have been trying to fix this code and so far after 10 hours have no succes my jsp page is coded like so...
    <head><title>JSP The Short Course - Lesson 13 </title></head>
    <jsp:useBean id="myBean" scope="session" class="examplebean.bean2" />
    <img src= "<%=myBean.getImage(1)%>">
    and the bean is coded like so
    package examplebean;
    import java.sql.* ;
    public class bean2 implements {
    public bean2() {}
    public javax.servlet.http.HttpServletResponse getImage(int p){ bufferedInputStream;
    Connection sqlca = null;
    Statement sqlStatement = null;
    ResultSet myResultSet = null;
    javax.servlet.http.HttpServletResponse response = null; i = null;
    int popo = 0;
    try {
    String theDatabase = "jdbc:sybase:Tds:compserver:5000/syb3026";
    sqlca = DriverManager.getConnection(theDatabase,"syb3026","oohyeahh");
    sqlStatement = sqlca.createStatement();
    myResultSet = sqlStatement.executeQuery("select Product_Picture from PRODUCT_TABLE where Product_Id = " + p + " ");
    /* Construct the heading for the table */
    /* Move to next row and & its contents
    to the html output */
    while( {
    byte[] pepe = myResultSet.getBytes("Product_Picture");
    popo = pepe.length;,0,popo);
    bufferedInputStream = new; byteArrayOutputStream = new;
    int start = 0;
    int length = 1024;
    byte[] buff = new byte[popo];
    int bytesRead;
    while(-1 != (bytesRead =, 0, popo))) {
    byteArrayOutputStream.write(buff, 0, bytesRead);
    response.setContentLength( byteArrayOutputStream.size() );
    response.getOutputStream().write( byteArrayOutputStream.toByteArray() );
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
    catch (SQLException e) {
    System.out.println(" Error: SQL error of: " + e.getMessage());
    catch (Exception e) {
    System.out.println(" Error: JDBC Class creation: " + e.getMessage());
    finally {
    try {
    catch(SQLException e) {
    System.out.println(" Error: Closing connection: " + e.getMessage());
    return response;

    maybe not so complex
    if ({ 
    buf = RS_photo.getBytes(1);
    OutputStream out = response.getOutputStream();
    }catch (Exception e){ 
    //throw e;

  • How can I get the image width and height stored in database?

    Hi!I write s servlet to display images store in database.but how can I get the image width and height?

    Have you tryed using PJA or a similar library?
    I presume you get java.lang.NoClassDefFoundError on the line :

  • 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 package and view the properties of the image. But unable to retrive the image as such to be displayed.
    Thanking You

    This might help...
    import javax.imageio.*;
    import javax.swing.*;
    import java.awt.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import oracle.sql.* ;
    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("Image not found! ");
    //actionLabel.setText(prefix + source.getText() + "\"");
    public ImageIcon createImageIcon(String key)
    Image image = null;
    ImageIcon imgIcon = null;
         // 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 =;
    // Create Image Icon from ImageInputStream
    if (null != image) imgIcon = new ImageIcon(image);
    } catch (Exception e)
    System.out.println("exception raised " + e);
    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);
    label = new JLabel("Image not found! ");
    // Create layout
    GridBagLayout gridBag = new GridBagLayout();
    // Create panel to draw in
    JPanel pane = new JPanel();
    GridBagConstraints c = new GridBagConstraints();
    JScrollPane scrollPane = new JScrollPane(label,
    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);
    // Add fields for input
    JLabel promptLabel = new JLabel("Please enter DB key: ");
    pane.add(textField, c);
    return pane;
    public static void main(String[] args)
    String key = "1";
    } 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) {
    public InputStream getDBInputStream(OracleConnection con, String key)
    InputStream is = null;
         int index = 0;
         Statement s = con.createStatement();
         OracleResultSet rs =
         (OracleResultSet)s.executeQuery("select * from images " +
    "where item_id = " + key );
         if ( // 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);
    return is;
    public OracleConnection connect() throws Exception
    String connectString;
    Class.forName ("oracle.jdbc.driver.OracleDriver");
    connectString = "jdbc:oracle:oci8:@orcl";
    OracleConnection con = (OracleConnection)
    return con;

Maybe you are looking for

  • Dynamic Filter Capabilities

    Hello, We are trying to write a query that will allow an end user to select a "BOM" number from a selection field, and based on the "BOM" number selected, allow the user to select from the available dates where this BOM has been changed.  I wrote the

  • Restart Process Chains

    I created a process chain that has 3 text file master data loads using the LOADING process type on version BW 3.0B.  If I delete the text file for one of the loads, the load will fail and I would like to restart the load from the failure point.  When

  • Looping a query without cursor

    Hi everybody i want to know that is there is any way by which we can loop through Resultset of a query without using cursor for loop in plsql vipul

  • Apache with WLS plugin and welcome page problems

    Hi,           Does anyone know to solve this problem ?           It works when i'm accessing my webapp directly on the wlserver           Thru Apache i have to enter the name of the startpage.           ie.  (not

  • Restore Recovery Partition

    I deleted my Recovery Partition by mistake and i dont have any Recovery disk. Its HP folio with windows 7! Can somebody please help me with what i can do about it!!! Thanks