j'ai un champ varchar qui peut contenir des apostrophes alors l'instruction SQL me retourne une exception
code d'insertionjdbc4.MySQLSyntaxErrorException:
code modifiaction
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 String query = "INSERT INTO article (titre,article,image,matricule_auteur,code_domaine_domaine,num_mag_magazine) VALUES (?,?,?,?,?,?)"; try (PreparedStatement stat = cnx.prepareStatement(query)){ stat.setString(1,titre); stat.setString(2,article); stat.setBinaryStream(3, fis); stat.setInt(4,auteur); stat.setInt(5,domaine); stat.setInt(6,mag); stat.executeUpdate();
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 String query = "UPDATE article set titre='"+txtTitre.getText()+"'," + "article='"+txtArticle.getText()+"'," + "image="+fis+"," + "code_domaine_domaine="+codeDom+"," + "num_mag_magazine="+cmbMag.getSelectedItem().toString()+"," + "matricule_auteur="+mat+" WHERE n_article="+numArt; stat = cnx.prepareStatement(query); stat.executeUpdate();
Partager