0

I have a Java program which should load an image from an SQL database and display said image on screen.

The image path can be returned fine, as I have printed out the path returned. The image does exist in the correct path too.

Now, I've tried hardcoding the path into the program and it prints the image fine, however, when loading the image using the path returned from the SQL database it won't load.

The image path is "images\image1.jpg"

Can you please tell me what the problem could be - thanks.

lblContent.setIcon(new ImageIcon("images\\test1.jpg"));

Hardcoded works fine ^

lblContent.setIcon(new ImageIcon(q2.get(6)));

Database retrieval does not ^

Now, I did get this working once, but can't for the life of me remember it.

user3176804
  • 49
  • 1
  • 2
  • 7
  • If you print `q2.get(6)` it returns the same path? Try evaluating `q2.get(6).equals("images\\test1.jpg")`. Maybe the slashes are wrong, or there are spaces before or after the returned String... Also, make sure `q2.get(6)` is actually a String - when an object is print out, it can be converted to a String, but it does not mean it is a String, and an incorrect ImageIcon constructor could be called. – Luan Nico Apr 06 '15 at 17:51
  • Might want to refer this : http://stackoverflow.com/questions/23190614/store-and-view-images-in-java-database-netbeans – Saagar Elias Jacky Apr 06 '15 at 17:52

0 Answers0