Modification de la base de donnee a partir de java

deathprog Messages postés 6 Date d'inscription mercredi 19 août 2009 Statut Membre Dernière intervention 26 août 2009 - 19 août 2009 à 16:17
Nicki_5595 Messages postés 5 Date d'inscription samedi 21 mars 2020 Statut Membre Dernière intervention 14 octobre 2021 - 14 oct. 2021 à 10:46
bonjour ;

voila j'ai un problème je sais pas comment modifier ma table de base de donnée depuis java pourtant je peux insérer supprimer et afficher.
voila le code :

public int modify(){[code=java]
       String SQL "UPDATE stagiaire
SET NOM "+getNom()+" , PRENOM = "+getPrenom()+", AGE = "+getAge()+",TEL = "+getTel()+",CODE_ECOLE ="+getCode_ecole()+" WHERE CODE = "+getCode()+"";
return this.Req_LMD(SQL);

}/code

public int Req_LMD(String req)
    {
        int v=0;
        System.out.println(req);
        if(this.Connexion())
        {
                Statement Stat=null;
                try {
                        Stat=(Statement) Con.createStatement();
                        v= Stat.executeUpdate(req);
                }
                catch (Exception e) { e.printStackTrace();}
                this.Deconnexion();
                System.out.println("fini");
        }
        System.out.println("Nbre de lignes validé : "+v);
        return v;
    }


et il m'envoi cette erreur la:
UPDATE stagiaire SET NOM saad , PRENOM saad, AGE = 23,TEL = 234,CODE_ECOLE =345  WHERE CODE = 0
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Champ 'saad' inconnu dans field list
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.Util.getInstance(Util.java:381)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)
        at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1634)
fini
        at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1553)
Nbre de lignes validé : 0



svp aidez moi !!

1 réponse

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
19 août 2009 à 16:39
Salut,

C'est que ta requête n'est pas correcte : Il faut entourer les chaînes de caractères par des apostrophes :

public int modify(){

       String SQL = "UPDATE stagiaire
SET NOM '"+getNom()+"' , PRENOM '"+getPrenom()+"', AGE = "+getAge()+",TEL = "+getTel()+",CODE_ECOLE ="+getCode_ecole()+" WHERE CODE = "+getCode()+""; 
return this.Req_LMD(SQL); 

}

______________________________________
DarK Sidious
1
deathprog Messages postés 6 Date d'inscription mercredi 19 août 2009 Statut Membre Dernière intervention 26 août 2009 1
20 août 2009 à 22:15
waw ça a marché enfin merci bcp pour ton aide j'ai passé 2 jours avec ce problème
merci
1
Nicki_5595 Messages postés 5 Date d'inscription samedi 21 mars 2020 Statut Membre Dernière intervention 14 octobre 2021
14 oct. 2021 à 10:46
Votre réponse a été utile pour moi aujourd’hui Merci.
0
Rejoignez-nous