vendredi 27 février 2015

Insertion of image in BLOB attribute in SQL is not working

I have a field in the database that corresponds to an BLOB image. I am trying to use the following command to insert a picture to the database using java.


My Code:



String sql = "INSERT INTO table (image) VALUES(?)";
BufferedImage originalImage = ImageIO.read(new File("/Users/John/Desktop/logo.png"));

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( originalImage, "png", baos );
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();


PreparedStatement ps = connection.prepareStatement(sql);
ps.setBytes(1, imageInByte);
ps.executeUpdate();


I don't have any run time errors the only problem is with the value in the database. My database now contains a value in the image attribute:



?.png

Aucun commentaire:

Enregistrer un commentaire