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 :

NetBeans ne m'affiche pas le contenu de ma table : problème ODBC


Sujet :

JDBC Java

  1. #281
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    getDateFin renvoi un objet String je pense :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        public String getDateFin()
        {
            return dateFin;
        }
    Déclaration de datefin :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private String dateFin;

  2. #282
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    Du coup grosse confusion !

    Bon, alors dans la base, les colonnes sont bien de vrais champ date ?
    dateToDB transforme un String "04/11/2016" (qui n'est pas un objet Date) en un autre String "2016-11-04"

    Tu peux poster le code de la requête ?

  3. #283
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    Oui m'sieur, vrai champ date !
    Requête de base :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String query2 = "SELECT Annexe.IdAnnexe, NomCharge, PrenomCharge, DateCreation, DateDeb, DateFin, NomInstallation, NomZone FROM Annexe, ChargeAffaire, Zone, Installation WHERE Annexe.IdZone = Zone.IdZone AND Zone.IdInstallation = Installation.IdInstallation AND Annexe.Matricule = ChargeAffaire.Matricule AND DateDeb <= '"+Utilitaire.formaterDateRequete(date)+"' AND DateFin >= '"+Utilitaire.formaterDateRequete(date)+"';";
    Fonction formaterDateRequete:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        /* Méthode permettant de formater une date en MM/dd/aaaa pour les requêtes */
        public static String formaterDateRequete(Date date)
        {
            String format = "yyyy-MM-dd";
            java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat(format);
            return formater.format(date);
        }
    résultat:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    query2 : SELECT Annexe.IdAnnexe, NomCharge, PrenomCharge, DateCreation, DateDeb, DateFin, NomInstallation, NomZone FROM Annexe, ChargeAffaire, Zone, Installation WHERE Annexe.IdZone = Zone.IdZone AND Zone.IdInstallation = Installation.IdInstallation AND Annexe.Matricule = ChargeAffaire.Matricule AND DateDeb <= '2016-11-04' AND DateFin >= '2016-11-04';

  4. #284
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    '2016-11-04' est une chaîne de caractères représentant une date au format ANSI (yyyy-mm-dd)
    alors MySql peut le convertir directement en date.

    Ceci ne sera pas vrai pour une autre base de données (dans une autre application)
    On va laisser comme cela pour le moment à cause des délais,
    mais pour ton avenir en Java, il faudra traiter le problème autrement (PreparedStatement) dans d'autres applications

  5. #285
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    D'accord.

    A présent, cette fonction me pose problème :
    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
    public static void AffichageUpload(String query, JTable table, int ida)
        {
            System.out.print(" Avant le try \n");
            try
            {
                DefaultTableModel modele = (DefaultTableModel) table.getModel();
                Vector<Vector<String>> data = null;
                Connexion connexion = new Connexion();
                System.out.print(" Dans le try. query = "+query);
                ResultSet resultats = connexion.getResultSet(query);
                int i = 0;
                Utilitaire.centrerTable(table);
                System.out.print(" HHHHHHHHHHHHHH "+resultats.getDate(2));
                System.out.print("HHHHHHHHHHHHHH "+Utilitaire.formaterDate(resultats.getDate(2)));
                while(resultats.next())
                {
                    if(resultats.getInt(1) != ida)
                    modele.addRow(data);
                    table.setValueAt(resultats.getInt(1),i,0);
                    table.setValueAt(Utilitaire.formaterDate(resultats.getDate(2)),i,1);
                    table.setValueAt(Utilitaire.formaterDate(resultats.getDate(3)),i,2);
                    table.setValueAt(Utilitaire.formaterDate(resultats.getDate(4)),i,3);
                    table.setValueAt(resultats.getString(5),i,4);
                    i++;
                }
                resultats.close();
                connexion.closeConn();
            }
            catch(Exception ex)
            {
                System.out.println("Annexe : Erreur lors de l'affichage du tableau Upload! "+ex.getMessage());
                ex.printStackTrace();
            }
    Résultat :
    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
     Avant le try 
    Fri Nov 04 14:38:01 CET 2016 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.
    java.lang.NullPointerException
     Dans le try. query = SELECT Annexe.IdAnnexe, DateCreation, DateDeb, DateFin, NomSociete FROM Annexe, Societe, Realiser, ChefChantier WHERE Matricule = 'xxx' AND Annexe.IdAnnexe = Realiser.IdAnnexe AND Realiser.IdCC = ChefChantier.IdCC AND ChefChantier.idSociete = Societe.IdSociete AND Annexe.upload=False;Annexe : Erreur lors de l'affichage du tableau Upload! null
            at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2019)
            at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:1982)
            at coactivite2.Annexe.AffichageUpload(Annexe.java:314)
            at coactivite2.Fenetre.MenuOngletFocusGained(Fenetre.java:6238)
            at coactivite2.Fenetre.access$6000(Fenetre.java:30)
            at coactivite2.Fenetre$62.focusGained(Fenetre.java:3927)
            at java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:203)
            at java.awt.Component.processFocusEvent(Component.java:6177)
            at java.awt.Component.processEvent(Component.java:6044)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4651)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4481)
            at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
            at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:901)
    une piste mon cher Watson ?

  6. #286
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    Watson te dirait qu'en lisant la 1ère ligne de la StackTrace on voit que le problème vient de : com.mysql.jdbc.ResultSetImpl.getDate(...
    et Sherlock d'ajouter que l'erreur est de type NullPointerException

    que conclure de cette leçon de lecture ?

  7. #287
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    Ben justement ca ne me parle pas bcp

    Si je me penche sur getDate avec ctrl clique comme appris précédemment, je tombe là dessus (qui est dans resultSet.java):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java.sql.Date getDate(int columnIndex) throws SQLException;
    Je crois qu'il faut pas trop toucher là bas... :/

    Me reste la piste de NullPointerException... je vais aller lire la doc un peu pour voir d'où ca peut venir

  8. #288
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    Bon, le code incriminé est le suivant je pense :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    table.setValueAt(Utilitaire.formaterDate(resultats.getDate(2)),i,1);
                    table.setValueAt(Utilitaire.formaterDate(resultats.getDate(3)),i,2);
                    table.setValueAt(Utilitaire.formaterDate(resultats.getDate(4)),i,3);
    getDate doit essayer de chopper la valeur du champ à la position 2,3 et 4 dans la table (anciennement dateDebut_old etc...)

    Je vais essayer de modifier la position de ces champs dans la BDD.

  9. #289
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    C'est la bonne piste.
    Soit les champs ne sont plus dans le bon ordre
    soit ils renvoient des valeurs nulles

  10. #290
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    C'était effectivement ce problème là, une fois les columns à nouveau dans l'ordre, ca roule

    Et devine sur quoi on tombe pour la prochaine erreur ???
    ==> Excel !
    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
    java.lang.NullPointerException
            at coactivite2.Connexion.closeConn(Connexion.java:71)
            at coactivite2.FichierExcel.sousTraitant(FichierExcel.java:177)
            at coactivite2.Fenetre.jButtonValiderAjoutAnnexeOuiActionPerformed(Fenetre.java:7071)
            at coactivite2.Fenetre.access$5300(Fenetre.java:30)
            at coactivite2.Fenetre$55.actionPerformed(Fenetre.java:3574)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6288)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6053)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4651)
    Je vais regarder ca de plus près maintenant

  11. #291
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    Citation Envoyé par Spiicky Voir le message
    Je vais regarder ca de plus près maintenant
    maintenant que tu sais lire une StackTrace ...

  12. #292
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    Je ne comprend pas bien là non plus ...
    Apparemment le problème provient de la fermeture de la connexion et puisqu'on me renvoi un java.lang.NullPointerException j'en déduis que l'objet connexion pourrait être null ?
    Voici la fonction sousTraitant :
    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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    /* Génération et remplissage de l'encadré "Signer/Dater" pour les sous-traitants */
        public void sousTraitant(JTable jTableST) throws SQLException, WriteException
        {
            String nomST        = null;
            String nomCCST      = null;
            String fonctionCCST = null;
            String telCCST      = null;
    
            ResultSet resultats = null;
            Connexion connexion = new Connexion();
            for(int i = 0;i < jTableST.getRowCount(); i++)
            {
                ChefChantier.recupererIdCCST(jTableST, i);
                WritableFont font = new WritableFont(WritableFont.ARIAL, 10);
                WritableCellFormat format12 = new WritableCellFormat (font);
                format12.setAlignment(Alignment.CENTRE);
                format12.setBorder(Border.LEFT, BorderLineStyle.THIN);
    
                resultats = connexion.getResultSet("SELECT FonctionCC, NomCC, PrenomCC FROM ChefChantier WHERE IdCC = "+ChefChantier.recupererIdCCST(jTableST, i)+";");
                System.out.print("SELECT FonctionCC, NomCC, PrenomCC FROM ChefChantier WHERE IdCC = "+ChefChantier.recupererIdCCST(jTableST, i)+";");
    
                while(resultats.next())
                {
                    fonctionCCST = resultats.getString(1);
                    nomST = (String) jTableST.getValueAt(i , 0);
                    nomCCST = (String) resultats.getString(2)+" "+resultats.getString(3);
                    telCCST = (String) jTableST.getValueAt(i , 3);
                    for(int r=0; r<4; r++)
                    {
                        sheet.insertRow(52);
                        Label label25 = new Label(0, 52, "", format12);
                        sheet.addCell(label25);
                    }
                    sheet.mergeCells(3, 52, 4, 52);
                    sheet.mergeCells(4, 53, 5, 53);
                    WritableCellFormat format = new WritableCellFormat (font);
                    format.setAlignment(Alignment.CENTRE);
                    format.setBorder(Border.ALL, BorderLineStyle.THIN);
                    WritableCellFormat format2 = new WritableCellFormat (font);
                    format2.setAlignment(Alignment.RIGHT);
                    format2.setBorder(Border.LEFT, BorderLineStyle.THIN);
                    WritableCellFormat format3 = new WritableCellFormat (font);
                    format3.setAlignment(Alignment.RIGHT);
                    WritableCellFormat format4 = new WritableCellFormat (font);
                    format4.setAlignment(Alignment.LEFT);
                    WritableCellFormat format5 = new WritableCellFormat (font);
                    format5.setAlignment(Alignment.LEFT);
                    format5.setBorder(Border.RIGHT, BorderLineStyle.THIN);
                    WritableCellFormat format13 = new WritableCellFormat (font);
                    format13.setAlignment(Alignment.LEFT);
                    format13.setBorder(Border.RIGHT, BorderLineStyle.THIN);
                    format13.setBorder(Border.TOP, BorderLineStyle.THIN);
                    WritableCellFormat format6 = new WritableCellFormat (font);
                    format6.setAlignment(Alignment.RIGHT);
                    format6.setBorder(Border.LEFT, BorderLineStyle.THIN);
                    WritableCellFormat format7 = new WritableCellFormat (font);
                    format7.setBorder(Border.BOTTOM, BorderLineStyle.THIN);
                    WritableCellFormat format8 = new WritableCellFormat (font);
                    format8.setBorder(Border.BOTTOM, BorderLineStyle.THIN);
                    WritableCellFormat format9 = new WritableCellFormat (font);
                    format9.setBorder(Border.BOTTOM, BorderLineStyle.THIN);
                    WritableCellFormat format10 = new WritableCellFormat (font);
                    format10.setBorder(Border.RIGHT, BorderLineStyle.THIN);
                    WritableCellFormat format11 = new WritableCellFormat (font);
                    format11.setBorder(Border.LEFT, BorderLineStyle.THIN);
                    Label label5 = new Label(3, 52, "pour la société :", format2);
                    Label label6 = new Label(5, 52, nomST, format4);
                    Label label7 = new Label(6, 52, "date :", format3);
                    Label label8 = new Label(7, 52, "", format5);
                    Label label9 = new Label(3, 53, "nom :", format2);
                    Label label10 = new Label(4, 53, nomCCST, format4);
                    Label label11 = new Label(3, 54, "fonction :", format2);
                    Label label12 = new Label(4, 54, fonctionCCST, format4);
                    Label label13 = new Label(6, 54, "Signature :", format3);
                    Label label14 = new Label(7, 53, "", format5);
                    Label label15 = new Label(7, 54, "", format5);
                    Label label16 = new Label(7, 55, "", format5);
                    Label label17 = new Label(7, 55, "", format2);
                    Label label18 = new Label(3, 55, "", format8);
                    Label label19 = new Label(4, 55, "", format7);
                    Label label20 = new Label(5, 55, "", format7);
                    Label label21 = new Label(6, 55, "", format7);
                    Label label22 = new Label(7, 55, "", format9);
                    Label label23 = new Label(2, 55, "", format10);
                    Label label24 = new Label(8, 55, "", format11);
                    Label label28 = new Label(7, 52, "", format13);
                    sheet.addCell(label28);
                    sheet.addCell(label5);
                    sheet.addCell(label6);
                    sheet.addCell(label7);
                    sheet.addCell(label8);
                    sheet.addCell(label9);
                    sheet.addCell(label10);
                    sheet.addCell(label11);
                    sheet.addCell(label12);
                    sheet.addCell(label13);
                    sheet.addCell(label14);
                    sheet.addCell(label15);
                    sheet.addCell(label16);
                    sheet.addCell(label17);
                    sheet.addCell(label18);
                    sheet.addCell(label19);
                    sheet.addCell(label20);
                    sheet.addCell(label21);
                    sheet.addCell(label22);
                    sheet.addCell(label23);
                    sheet.addCell(label24);
                }
                resultats.close();
            }
            connexion.closeConn();
        }
    Pourtant je pense l'ouvrir, l'utiliser et la fermer correctement non ?
    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
    java.lang.NullPointerException
            at coactivite2.Connexion.closeConn(Connexion.java:71)
            at coactivite2.FichierExcel.sousTraitant(FichierExcel.java:177)
            at coactivite2.Fenetre.jButtonValiderAjoutAnnexeOuiActionPerformed(Fenetre.java:7071)
            at coactivite2.Fenetre.access$5300(Fenetre.java:30)
            at coactivite2.Fenetre$55.actionPerformed(Fenetre.java:3574)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6288)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6053)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4651)

  13. #293
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    Je ne vois pas bien sur le code posté mais il me semble que
    se trouve à l'intérieur de la boucle
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    for(int i = 0;i < jTableST.getRowCount(); i++)
    du coup, ça plante au 2ème tour de boucle

  14. #294
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    Mais non ! j'ai justement bien vérifié et ce n'est pas le cas !
    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 sousTraitant(JTable jTableST) throws SQLException, WriteException
        {
            ...
            ResultSet resultats = null;
            Connexion connexion = new Connexion();
            for(int i = 0;i < jTableST.getRowCount(); i++)
            { 
                ...
                resultats = connexion.getResultSet("SELECT FonctionCC, NomCC, PrenomCC FROM ChefChantier WHERE IdCC = "+ChefChantier.recupererIdCCST(jTableST, i)+";");
                while(resultats.next())
                {
                ...
                }
                resultats.close();
            }
            connexion.closeConn();
        }

  15. #295
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    Et Connexion connexion ne serait pas déclaré en variable de classe des fois ?

    Sinon il n'y a plus qu'a passer le débug !

    mets un point d'arrêt sur connexion.closeConn() et lance l'application en mode débug.

  16. #296
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    Citation Envoyé par Népomucène Voir le message
    Et Connexion connexion ne serait pas déclaré en variable de classe des fois ?
    Je pense que c'est ça étant donné que l'erreur se reproduit 3 fois (de suite) sur le même fichier dans un contexte similaire.
    Si Connexion connexion est déclaré en variable de classe, je dois me débrouille pour qu'il devient accessible sans passé par du static c'est ça ?

    J'effectue tout de même le point d'arrêt :
    Nom : Sans titre.jpg
Affichages : 130
Taille : 144,6 Ko

  17. #297
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    Dans ta méthode sousTraitant(JTable jTableST) change le nom de ta variable Connexion.
    nomme-la comme cela :
    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
    public void sousTraitant(JTable jTableST) throws SQLException, WriteException
        {
            ...
            ResultSet resultats = null;
            Connexion connexionSousTraitant = new Connexion();
            for(int i = 0;i < jTableST.getRowCount(); i++)
            { 
                ...
                resultats = connexionSousTraitant.getResultSet("SELECT FonctionCC, NomCC, PrenomCC FROM ChefChantier WHERE IdCC = "+ChefChantier.recupererIdCCST(jTableST, i)+";");
                while(resultats.next())
                {
                ...
                }
                resultats.close();
            }
            connexionSousTraitant.closeConn();
        }

  18. #298
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    Ah tu penses que plusieurs connexion interféraient entre elles ?

    Correction effectué sans succès

    Au passage, l'Excel se lance et est rempli correctement ! Donc super good news !

  19. #299
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 792
    Points
    4 792
    Par défaut
    Là c'est un joli mystère.
    Même si la méthode est appelée plusieurs fois, un objet Connexion est créé à chaque fois ...

  20. #300
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2015
    Messages
    340
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2015
    Messages : 340
    Points : 31
    Points
    31
    Par défaut
    Bon de toute manière les utilisateurs ne verront rien... Et cela n'a pas l'air d'entraver le fonctionnement de l'application...

    Lors de mes tests, je me suis penché sur la question des requêtes préparées.
    Par exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Connexion connexion = new Connexion();
                        connexion.execSql("INSERT INTO Risque (LibelleRisque, Prevention, IdAnnexe) VALUES ('"+risque1.getLibelleRisque()+"', '"+risque1.getPrevention()+"', "+annexe.getIdAnnexe()+");");
                        connexion.closeConn();
    Pour l'obtenir en requête préparé, je dois faire ceci c'est bien ca ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Connexion connexion = new Connexion();
                        PreparedStatement ps = connexion.con.prepareStatement("INSERT INTO Risque (LibelleRisque, Prevention, IdAnnexe) VALUES (?, ?, ?);");
                        ps.setString(1, risque1.getLibelleRisque());
                        ps.setString(2, risque1.getPrevention());
                        ps.setInt(3, annexe.getIdAnnexe());
                        ps.executeUpdate();
                        connexion.closeConn();
    Je n'ai pas d'erreur pour le moment...
    Je vais reprendre tout ca lundi, passe un bon week end Népo et merci encore !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. ListView qui change de taille mais n'affiche pas le contenu d'une ObservableCollection
    Par Atellane dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 14/08/2014, 10h46
  2. DataGrid n'affiche pas le contenu de certaines colonnes d'un Datatable
    Par alucia dans le forum Windows Presentation Foundation
    Réponses: 3
    Dernier message: 20/09/2013, 13h39
  3. .load qui n'affiche pas le contenu de la page
    Par tonydu91 dans le forum jQuery
    Réponses: 4
    Dernier message: 06/04/2013, 23h58
  4. [SimpleXML] Problème avec simpleXML : il n'affiche pas le contenu de mon élément
    Par ploxien dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 05/05/2007, 19h43
  5. GUI Java par netbeans - ne s'affiche pas
    Par G_angel dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 31/01/2007, 11h38

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