How to get Image from Database(MySQL) using Java in NetBeansIDE

How to get Image from Database(MySQL) in Java with NetBeansIDE.

Note: Image is of Blob/LongBlob type in Database.

1. Open NetBeansIDE.

2. In your project make a JFrame form (say NewForm)

2.1 Add a button and a label(to display the image) in it.

3. Right Click on Button and Goto Events~action~actionPerformed

3.1 In actionPerformed method write code for connection.
3.2 Get the image in Byte array.

4. Import mysql connector jar file.

5. Run the JFrame Form file.

6. Finish.

Facebook Page:

Blog :



  1. i follow your source code, but i have error in row 93(in your Sourcode):
    or in this sourcode =>  image = getToolkit().createImage(imageBytes);
    error on getToolkit().createImage(imageBytes)..
    what declaration of getToolkit() and createImage(imageBytes)?
    or what should i import in lib for this code?
    please respons, and sorry for my english

  2. i have error in this line : img=getToolkit().createImage(imageBytes);
    Error:variable imageBytes might not have been initialised.. so i initialized as: byte[] imageBytes = null;
    now the runtime Error :
    java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). How to solve this

  3. Thank you so much it worked perfectly..And can you please make the same video for insertion ,deletion and updating images please.
    I have mini project..Have to do it..
    Thank you 😊😊

Comments are closed.