IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JDBC Java Discussion :

Jtable et update sql


Sujet :

JDBC Java

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Janvier 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Gabon

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Alimentation

    Informations forums :
    Inscription : Janvier 2013
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Jtable et update sql
    Bonjour à tous !

    Je permet de vous interpeller car j'ai grand besoin de votre aide. Je suis novice en java et j'ai un code qui me refroidi dans le projet que je réalise.
    Je souhaite mettre à jour une base SQL à partir d'un document importer dans Jtable.
    L'importation du document se passe bien, mais le code de mise à jour ne me récupère que la ligne 0 sur près de 200 lignes.

    Voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
        private void ButtonPointsActionPerformed(java.awt.event.ActionEvent evt) {                                             
     
            int rows = TableImport.getRowCount();
            for(int i= 0; i < rows; i++){
            // Mise à jour des points :
            String query ="UPDATE `clients` SET `Points`='"+TableImport.getValueAt(i, 8)+"' WHERE `Cartes`="+TableImport.getValueAt(i, 0);        
            executeSQLQuery(query,"Update");
            }
     
        }
    Merci pour votre apport.

  2. #2
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Janvier 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Gabon

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Alimentation

    Informations forums :
    Inscription : Janvier 2013
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Merci Robin56 pour cette correction !

    J'ai entre temps essayé de bidouillé à nouveau mais sans succès.

    Complément d'infos que je n'ai pas mis lors du post d'ouverture

    Pour me connecter à SQL :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    public void executeSQLQuery (String query, String update)
        {
     
            try{
                Import = importconnexion.ObtenirConnexion().createStatement();
                if ((Import.executeUpdate (query)) == 1)
                {
                    DefaultTableModel model = (DefaultTableModel) TableImport.getModel();
                    model.setRowCount(0);
     
                    JOptionPane.showMessageDialog(null,"Données mises à jour");
                }else{
                    JOptionPane.showMessageDialog(null,"Echec de mises à jour");
                }
            }catch (Exception ex){
                ex.printStackTrace();
            }
        }
    Et le code (modifié) pour mettre à jour la base SQL :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
        private void ButtonPointsActionPerformed(java.awt.event.ActionEvent evt) {                                             
     
            for(int i= 0; i < TableImport.getRowCount(); i++){
                for(int j = 0; j < TableImport.getColumnCount(); j++){
     
            // Mise à jour des points :
            String query ="UPDATE `clients` SET `Points`='"+TableImport.getValueAt(i, 8)+"' WHERE `Cartes`="+TableImport.getValueAt(i, 0);        
            executeSQLQuery(query,"Update");
            }
            }
        }
    L'erreur généré lors l’exécution de la requête :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    Chargement du pilote reussi
    Mon Jan 21 18:32:28 WAT 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
    Connexion à la BD reussie
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
    	at java.util.Vector.elementAt(Vector.java:477)
    	at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:648)
    	at javax.swing.JTable.getValueAt(JTable.java:2720)
    	at clients_sodigab.Imports.ButtonPointsActionPerformed(Imports.java:169)
    	at clients_sodigab.Imports.access$100(Imports.java:22)
    	at clients_sodigab.Imports$2.actionPerformed(Imports.java:107)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    	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:6539)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    	at java.awt.Component.processEvent(Component.java:6304)
    	at java.awt.Container.processEvent(Container.java:2239)
    	at java.awt.Component.dispatchEventImpl(Component.java:4889)
    	at java.awt.Container.dispatchEventImpl(Container.java:2297)
    	at java.awt.Component.dispatchEvent(Component.java:4711)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    	at java.awt.Container.dispatchEventImpl(Container.java:2283)
    	at java.awt.Window.dispatchEventImpl(Window.java:2746)
    	at java.awt.Component.dispatchEvent(Component.java:4711)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    	at java.awt.EventQueue.access$500(EventQueue.java:97)
    	at java.awt.EventQueue$3.run(EventQueue.java:709)
    	at java.awt.EventQueue$3.run(EventQueue.java:703)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    	at java.awt.EventQueue$4.run(EventQueue.java:733)
    	at java.awt.EventQueue$4.run(EventQueue.java:731)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
    Amicalement.

  3. #3
    Membre averti Avatar de pmboutteau
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2005
    Messages
    601
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Santé

    Informations forums :
    Inscription : Février 2005
    Messages : 601
    Points : 420
    Points
    420
    Par défaut
    Problème d'index. Tu dépasses la capacité de ton tableau.
    ours ours !! Au début elle est froide mais après elle est bonne!

Discussions similaires

  1. Update Sql sur une Query Filtré
    Par Soulama dans le forum Bases de données
    Réponses: 4
    Dernier message: 26/10/2006, 14h47
  2. Erreur Update SQL + ASP
    Par dragonfly dans le forum ASP
    Réponses: 3
    Dernier message: 23/10/2006, 14h04
  3. [c#/vs2005] UPDATE: SQL -> Oracle
    Par cnguyen dans le forum Oracle
    Réponses: 14
    Dernier message: 05/07/2006, 10h40
  4. Update sql, avec une table à deux colonnes ...
    Par dcz dans le forum Langage SQL
    Réponses: 8
    Dernier message: 04/04/2006, 18h06
  5. [Oracle 9.1] Plantage update SQL et Timestamp
    Par ftrifiro dans le forum Oracle
    Réponses: 6
    Dernier message: 06/10/2005, 14h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo