i have an image stored in the column( img) of mysql table albums. the format is blob.
i do not no how to retreive it from the table and display it in a label img1 in my netbeans project.
how do i write the resultset code and display it on the label.
please help me.

steps for setting image for Label:

  1. create a image file as follows

    File image = new File("D:\mysample.jpg");

  2. i think you know how to read image data from database.once you get the resultset object do as follows i mean store image column data into above file

    // after getting resultset 
    
          FileOutputStream fos = new FileOutputStream(image);
    
          byte[] buffer = new byte[1];
           is = resultSet.getBinaryStream("img_clumn_no");
          while (is.read(buffer) > 0) {
            fos.write(buffer);
          }
          fos.close()
          // then close the connection 
    

3.then set the above image file path to label as follows

   // set the above image path to label as follows 

    label.setIcon(new ImageIcon(image.getAbsolutePath()));

     //or you can put directly 

    your_label.setIcon(new ImageIcon("D:\\mysample.jpg"));

check it once it gives the proper output to your problem or not

happy coding

the problem is i have a table in java when i click a row data srelated to that row will be displayed into the labels.
here is my query

String sql='select ename,img from albums where code='+acode+'';';

img is the image column .how do i write the result set for this
is it .can i use this code

String image=res.getString("img");
but i am not able to display it in the label.
i stored the image in mysql table as the image's path.

first let me get clarity on your project type

i forgot to ask you previously

is your project on web based or swing based?

i am getting little bit confusion on your requirement which is posted above ( ru talking about Jlabel or label which is using in Html)

thats the reason i am asking you

please breifly explain your problem clearly so that we are here to help you

Edited 3 Years Ago by radhakrishna.p: asking for exact requirement

This article has been dead for over six months. Start a new discussion instead.