DEVFYI - Developer Resource - FYI

How can I insert images into a Mysql database?

JDBC Interview Questions and Answers


(Continued from previous question...)

How can I insert images into a Mysql database?

This code snippet shows the basics:

File file = new File(fPICTURE);
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps =
ConrsIn.prepareStatement("insert into dbPICTURE values (?,?)");

// ***use as many ??? as you need to insert in the exact order***
ps.setString(1,file.getName());
ps.setBinaryStream(2,fis,(int)file.length());
ps.close();
fis.close();

(Continued on next question...)

Other Interview Questions