Précédent   Forum des professionnels en informatique > Bases de données > MySQL > Débuter
Débuter Forum d'entraide pour débuter avec MySQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 06/01/2012, 16h17   #1
Candidat au titre de Membre du Club
 
Homme
Étudiant
Inscription : mai 2011
Messages : 124
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : mai 2011
Messages : 124
Points : 11
Points : 11
Par défaut Problème avec INSERT dans MySQL

Bonjour, je viens de faire ma requête Insert dans ma classe en java mais celle-ci ne marche pas, pouvez-vous me dire pourquoi ?
Voici le code
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
String sql1 = "INSERT INTO Jouer (Njeu, DateJeu, HeureJeu, RésumeJeu, ObsJeu, Commune, LieuJeu, Details) VALUES ('" + jeu + "','" + date + "','" + heure + "','" + resume + "','" + observations + "','" + commune + "','" + lieu + "','" + details + "')";
        PreparedStatement stmt = NULL;
        ResultSet rs1 = NULL;
        try {
            stmt = (PreparedStatement) con1.prepareStatement(sql1);
        } catch (SQLException ex) {
            Logger.getLogger(saisieAccidents.class.getName()).log(Level.SEVERE, NULL, ex);
        }
        try {
            rs1 = stmt.executeQuery(sql1);
        } catch (SQLException ex) {
            Logger.getLogger(saisieAccidents.class.getName()).log(Level.SEVERE, NULL, ex);
        }
Cordialement et merci de votre future aide !
Bonne journée
Ercan67000 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/01/2012, 17h12   #2
Modérateur
 
Avatar de CinePhil
 
Homme Philippe Leménager
Ingénieur d'études en informatique
Inscription : août 2006
Messages : 11 029
Détails du profil
Informations personnelles :
Nom : Homme Philippe Leménager
Âge : 48
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Ingénieur d'études en informatique
Secteur : Enseignement

Informations forums :
Inscription : août 2006
Messages : 11 029
Points : 18 331
Points : 18 331
Envoyer un message via MSN à CinePhil
Citation:
Envoyé par Ercan67000 Voir le message
mais celle-ci ne marche pas, pouvez-vous me dire pourquoi ?
Parce qu'elle n'a pas de jambes !

Symptômes ?
- Pas de résultat ?
- Résultat inattendu ?
- Message d'erreur ?

As-tu testé la requête directement sur MySQL ?

As-tu vérifié que tes variables sont toutes valorisées ?

As-tu vérifié quelle requête est réellement envoyée à MySQL ?
__________________
Philippe Leménager. Ingénieur d'étude à l'École Nationale de Formation Agronomique.
Mon blog sur la conception des BDD, le langage SQL, le PHP avec Zend Framework...
« Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément ». (Nicolas Boileau)
À la maison comme au bureau, j'utilise Mandriva Linux ou Mageïa ! Soutenons l'industrie logicielle française !
Linuxiens, comptez-vous !
CinePhil est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/01/2012, 17h30   #3
Candidat au titre de Membre du Club
 
Homme
Étudiant
Inscription : mai 2011
Messages : 124
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : mai 2011
Messages : 124
Points : 11
Points : 11
Oui il n'y a pas de résultat dans la BDD, le message d'erreur est :
Citation:
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:490)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1467)
at accidentologie.saisieAccidents.jButton2ActionPerformed(saisieAccidents.java:514)
at accidentologie.saisieAccidents.access$200(saisieAccidents.java:9)
at accidentologie.saisieAccidents$3.actionPerformed(saisieAccidents.java:96)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Je ne peux pas la tester directement sur mysql vu que c'est une requete avec des variables..

mais variables correspondent tous a des textfields ou des combobox

Cordialement
Ercan67000 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/01/2012, 12h46   #4
Expert Confirmé
 
Homme
Inscription : mai 2002
Messages : 1 655
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 29
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : mai 2002
Messages : 1 655
Points : 2 657
Points : 2 657
bonjour,


google : java.sql.SQLException: Can not issue data manipulation statements with executeQuery()

=> 1er & 2eme résultat
punkoff est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/01/2012, 09h17   #5
Candidat au titre de Membre du Club
 
Homme
Étudiant
Inscription : mai 2011
Messages : 124
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : mai 2011
Messages : 124
Points : 11
Points : 11
Merci de votre réponse, je viens d’exécuter la requête avec un executeUpdate à la place de executeQuery mais j'ai toujours le message d'erreur.. Que dois-je faire ?

Cordialement et merci encore de votre aide
Ercan67000 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h24.


 
 
 
 
Partenaires

Hébergement Web