Help im displaying image from database in java

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2009
Posts: 4
Reputation: anu6189 is an unknown quantity at this point 
Solved Threads: 0
anu6189 anu6189 is offline Offline
Newbie Poster

Help im displaying image from database in java

 
0
  #1
Jul 20th, 2009
Hey all,
ive been searching for a long time and i want to know how am i suppose to display an image that is stored in the database(SQL) in swings in java.
i inserted the data in the database as a image datatype(i hope thats right),now the thing is i want to display it on a JPanel or a JFrame.
i was thinking of storing it in the ImageIcon and then displaying it in a label, but how do i go about it..i mean can anyone pls help me with the actual code of displaying the image
Any help is appreciated!!Thanks in advance!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: Help im displaying image from database in java

 
0
  #2
Jul 22nd, 2009
Well you could start by this, assuming the image is in the same folder, or you can always add the path
  1. JLabel imageLabel=new JLabel(new ImageIcon("image.*extension*"));
  2. imageLabel.setHorizontalAlignment(JLabel.CENTER);
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: anu6189 is an unknown quantity at this point 
Solved Threads: 0
anu6189 anu6189 is offline Offline
Newbie Poster

Re: Help im displaying image from database in java

 
0
  #3
Jul 22nd, 2009
ok i got that much done. but after that??
i mean now how do i get the picture from a database to be loaded into that ImageIcon..
i was actually thinking of using image icon part of labels, but the place where im stuck is what to do with the result set
i mean what method do i use to set the image from the database into the image icon with the help of ResultSet object..
or if there is another method to achieve it, please do reply..
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: anu6189 is an unknown quantity at this point 
Solved Threads: 0
anu6189 anu6189 is offline Offline
Newbie Poster

Re: Help im displaying image from database in java

 
0
  #4
Jul 22nd, 2009
ok i got that much done. but after that??
i mean now how do i get the picture from a database to be loaded into that ImageIcon..
i was actually thinking of using ImageIcon, but the place where im stuck is what to do with the ResultSet object to get the image
i mean what method do i use to set the image from the database into the image icon with the help of ResultSet object..
or if there is another method to achieve it, please do reply..
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: Help im displaying image from database in java

 
0
  #5
Jul 23rd, 2009
I am not quite farmiliar with database programing in Java. But what does ResultSet return? If it is a path then you would need to include that path in the "image.jpg" area to get the image as in "//path/image.jpg". Otherwise if it returns something else (that I am not sure of) then my suggestion would be, when saving an image to the database, dont actually save the image but save a certain string/character or number to this slot. assign this number to the image and save the image in a certain directory or something. when this image is called, the character/string or number is used to look up the image in the directory. Hope this can help
Last edited by joshmo; Jul 23rd, 2009 at 1:13 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,638
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Help im displaying image from database in java

 
0
  #6
Jul 23rd, 2009
  1. ....
  2. byte []b=rs.getBytes("columnname")
  3. ImageIcon img=new ImageIcon(b);
  4. ....
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: anu6189 is an unknown quantity at this point 
Solved Threads: 0
anu6189 anu6189 is offline Offline
Newbie Poster

Re: Help im displaying image from database in java

 
0
  #7
Jul 24th, 2009
Hey i tried that but i wasnt getting the output.i mean the other data are getting displayed but the image isnt coming. I put a text as "Image:" in the label to just know where the label is, and while executing, the text just moved a little bit.
Do i have to put the image in sql as IMAGE datatype??is that right of mine code??
And is it that the image is in some other folder and that it is supposed to be in the same folder as the program or something??
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC