Skip to content
Advertisement

Retrieving pictures from MySQL using Java

I have a question related to retrieving files from MySQL using JDBC. I managed to save a .png file from my desktop & retrieve it successfully, but I can’t read the file. It shows that the format is unsupported (eventhough I can open the original file without any issue).

Here’s the code:

Any ideas what could be the cause and how to fix it?

Advertisement

Answer

You have to use FileOutpuStream, because you have to write bytes not char. Also you column should be a blob.

Something like this should work

Imports are:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement