Skip to main content

The PreparedStatement does not save multiple images

No replies
Joined: 2010-03-15

good morning,

I have a three-tier application. I get the parameters of a form from a jsp and I record them in a

object. The latter contains fields of type String and type InputStream (images).
This item requires a service to go to the persistence layer. Now I use PreparedStatement for power

save this in the mysql database.
String (application) ----> varchar (BDD)
InputStream (application )-----> blob (BDD).

Here's a small snippet:

sql = "insert into t_annonce (ID SSTHEME, TITLE, CONTENT, PHOTOPR, PHOTOSC1, PHOTOSC2) values (?,?,?,?,?,?,?)";
connection = getConnection ();
PreparedStatement ps = connection.prepareStatement (sql);

ps.setString (1 objet.getId ());
ps.setString (2 objet.getSsTheme ());
ps.setString (3 objet.getTitre ());
ps.setString (4 objet.getContenu ());
ps.setBinaryStream (5 objet.getPhotopr ());
ps.setBinaryStream (6 objet.getPhotosc1 ());
ps.setBinaryStream (7 objet.getPhotosc2 ());
ps.executeUpdate ();

Question: PreparedStatement records all String fields and one field inputStream! not the other two!
I do not understand
Thank you for answer