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. #321
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    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 713
    Points : 4 792
    Points
    4 792
    Par défaut
    Oui, je sais la vie est dure ...

    Sinon, tu peux simplement mettre dans la méthode AffichageSociete :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    System.out.println("exécution de AffichageSociete ");
    comme ça (sans débug) tu sauras si c'est exécuté ou pas

  2. #322
    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
    Ouais c'est dure dure même lol

    Je confirme, le code est exécuté !
    Au passage, je suis tombé la dessus en cherchant :
    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
            /* Evènement lorsque la fenêtre devient la fenêtre courante */
            public void windowActivated(WindowEvent arg0)
            {
                /* Affichage de la liste des zones et installations dans le panneau d'administration */
                Utilitaire.reinitialiserTableau((DefaultTableModel)jTableZone.getModel());
                Zone.AffichageZone(jTableZone);
     
                /* Affichage de la liste des chargés d'affaires dans le panneau d'administration */
                Utilitaire.reinitialiserTableau((DefaultTableModel)jTableCharge.getModel());
                ChargeAffaire.AffichageCharge(jTableCharge);
     
                /* Affichage de la liste des sociétés dans le panneau d'administration */
                Utilitaire.reinitialiserTableau((DefaultTableModel)jTableSociete.getModel()); // Ce qui nous intéresse :)
                Societe.AffichageSociete(jTableSociete); // Ce qui nous intéresse :)
     
                /* Affichage de la liste des chef de chantiers dans le panneau d'administration */
                Utilitaire.reinitialiserTableau((DefaultTableModel)jTableCC.getModel());
                ChefChantier.AffichageCC(jTableCC);
            }
    Par contre, lorsque je fais ALT+F7 sur windowActivated, NB me dit qu'elle n'est utilisé qu'ici, lors de sa déclaration...
    Il y a un truc vraiment pas net quelque part !

  3. #323
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    ça pique les yeux

  4. #324
    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 andry.aime Voir le message
    ça pique les yeux
    Le vert (qui brule les yeux) ou le code (qui brule aussi les yeux lol) ?

  5. #325
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Le vert. Et puis colorer un code comme ça désactive la coloration syntaxique. Contente seulement de mettre des commentaires dans le code.

  6. #326
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    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 713
    Points : 4 792
    Points
    4 792
    Par défaut
    Citation Envoyé par andry.aime Voir le message
    ça pique les yeux
    C'est une application qui a été écrite par des générations de stagiaires !
    Il y a des strates géologiques de joyeusetés dans ce genre !

    Du coup, si tu supprime une société, ensuite tu fermes et tu ouvres à nouveau alors c'est à jour ???

  7. #327
    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
    C'est une application qui a été écrite par des générations de stagiaires !
    Il y a des strates géologiques de joyeusetés dans ce genre !
    haha, tes phrases sont fantastiques !!! (je rigole tout seul au boulot )

    Citation Envoyé par Népomucène Voir le message
    Du coup, si tu supprime une société, ensuite tu fermes et tu ouvres à nouveau alors c'est à jour ???
    Oui complètement !
    Si on ferme l'appli et qu'on la rouvre ca s'affiche correctement !
    ==> Pareil pour les 3 manips :ajout, modif et suppr !

    Donc on a deux bug majeur :
    - Le raffraichissement de se tableau (uniquement visuel car les requête bdds fonctionnement)
    - Ce soucis de connexion qu'on a pas trop identifié quand on créer une annexe...

    Allez, je suis bouillant Dernière ligne droite

  8. #328
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Re,

    Dans la méthode AffichageSociete, ajoute modele.fireTableDataChanged(); après avoir rechargé les données.

    A+.

  9. #329
    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 j'ai passé mon matin à refaire des requêtes qui n'était pas préparées... je supportais plus de voir ca lol

    Ensuite j'appliqué AffichageSociete en dernière instruction de chaque BTN (ajout, modifier et suppr).

    Citation Envoyé par andry.aime Voir le message
    Dans la méthode AffichageSociete, ajoute modele.fireTableDataChanged(); après avoir rechargé les données.
    Cela fonctionne parfaitement à présent !!! Merci bcp

    Me reste à traiter la question de la connexion qui plante bizarrement lors de la création d'une annexe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    java.lang.NullPointerException
            at coactivite2.Connexion.closeConn(Connexion.java:71)
            at coactivite2.FichierExcel.sousTraitant(FichierExcel.java:182)
            at coactivite2.Fenetre.jButtonValiderAjoutAnnexeOuiActionPerformed(Fenetre.java:7188)
            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)
    En fait, c'est toujours la fermeture de la connexion qui pose problème :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connexionSousTraitant2.closeConn();
    Népo, m'as conseillé de la renommer pour être sur qu'il n'y ai pas de conflit mais cela ne change pas l'incriminé

    Petite question au passage : c'est mieux de caster en faisant (Type) variable ou alors variable.toType ?

  10. #330
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    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 713
    Points : 4 792
    Points
    4 792
    Par défaut
    Citation Envoyé par Spiicky Voir le message
    Petite question au passage : c'est mieux de caster en faisant (Type) variable ou alors variable.toType ?
    (Type) variable : tu peux toujours essayer mais si c'est incompatible alors cela va planter.

    variable.toType : c'est plus sûr mais beaucoup d'objets n'ont pas cette méthode.

    sinon, en principe c'est équivalent.

    pour connexionSousTraitant2.closeConn(); tu peux re-poster le code ?

  11. #331
    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 bien sure :
    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
    113
    114
    115
        /* 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 connexionSousTraitant = 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);
                int idChefChantier = (int) ChefChantier.recupererIdCCST(jTableST, i);
                PreparedStatement ps    = connexionSousTraitant.getConnexion().prepareStatement("" +
                        "SELECT FonctionCC, NomCC, PrenomCC " +
                        "FROM ChefChantier " +
                        "WHERE IdCC = ?;");
                ps.setInt(1, idChefChantier);
                resultats = ps.executeQuery();
                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();
            }
            connexionSousTraitant.closeConn();
        }
    En espérant que ca pourrait aider !

  12. #332
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    at coactivite2.Connexion.closeConn(Connexion.java:71)
    at coactivite2.FichierExcel.sousTraitant(FichierExcel.java:182)
    at coactivite2.Fenetre.jButtonValiderAjoutAnnexeOuiActionPerformed(Fenetre.java:7188)
    at coactivite2.Fenetre.access$5300(Fenetre.java:30)
    at coactivite2.Fenetre$55.actionPerformed(Fenetre.java:3574)
    C'est dans la classe Connexion que tu as le NullPointerException.
    Tu nous montres cette classe?

    A+.

  13. #333
    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
    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
    package coactivite2;
     
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.sql.*;
     
    public class Connexion {
     
        private Connection con;
     
        public Connection getConnexion() {
            try {
                String url              = null;
                String fichier          = "X:/link/connexion.xml";
                FileInputStream ips     = new FileInputStream(fichier);
                InputStreamReader ipsr  = new InputStreamReader(ips);
                BufferedReader br       = new BufferedReader(ipsr);
                url = br.readLine();
                br.close();
     
                String pilote = "com.mysql.jdbc.Driver";
                Class.forName(pilote);
            } catch (Exception e) {
                  e.printStackTrace();
            }
     
            //connection a la base de données
            try {
                String DBurl        = "jdbc:mysql://IPv4/coactivitenew";
                String login        = "xxx";
                String password     = "xxx";
                con = DriverManager.getConnection(DBurl,login,password);
                java.util.Properties prop = new java.util.Properties();
                prop.put("charSet", "ISO-8859-1");
                con.setClientInfo(prop);
     
                return con;
            } catch (Exception e) {
                System.err.println("Erreur de connexion à la base de données!");
                System.err.println(e);
                e.printStackTrace();
                return con;
            }
        }
     
        public ResultSet getResultSet(String sql) {
            try {
                //System.out.print(sql);
                Statement requete   = getConnexion().createStatement();
                ResultSet rs        = requete.executeQuery(sql);
                return rs;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
     
        public void execSql(String sql) {
            try {
                //System.out.print(sql);
                Statement requete = getConnexion().createStatement();
                requete.executeUpdate(sql);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
     
        public void closeConn() {
            try {
                 con.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

  14. #334
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    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 713
    Points : 4 792
    Points
    4 792
    Par défaut
    Tu me dis que ça plante sur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connexionSousTraitant2.closeConn();
    mais dans le code posté de la méthode sousTraitant, on a :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      Connexion connexionSousTraitant = new Connexion();
    Ce n'est pas le même objet Connexion. On ne doit pas être sur la bonne classe ou méthode

  15. #335
    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
    En fait, ca plante :
    Sur connexionSousTraitant :
    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
    113
    114
    115
        /* 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 connexionSousTraitant = 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);
                int idChefChantier = (int) ChefChantier.recupererIdCCST(jTableST, i);
                PreparedStatement ps    = connexionSousTraitant.getConnexion().prepareStatement("" +
                        "SELECT FonctionCC, NomCC, PrenomCC " +
                        "FROM ChefChantier " +
                        "WHERE IdCC = ?;");
                ps.setInt(1, idChefChantier);
                resultats = ps.executeQuery();
                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();
            }
            connexionSousTraitant.closeConn();
        }
    Sur connexionSousTraitant2 :
    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
        /* Récupérer et générer une ligne pour les sous-traitants dans le tableau récapitulatif des sociétés */
        public void sousTraitant2(JTable jTableST) throws WriteException, SQLException
        {
            WritableFont font = new WritableFont(WritableFont.ARIAL, 10);
            WritableCellFormat format12 = new WritableCellFormat (font);
            format12.setAlignment(Alignment.CENTRE);
            format12.setBorder(Border.LEFT, BorderLineStyle.THIN);
            String nomST = null;
            String nomCCST = null;
            String fonctionCCST = null;
            String telCCST = null;
     
            try{
                Connexion connexionSousTraitant2 = new Connexion();
                ResultSet resultats = null;
                for(int i = 0;i < jTableST.getRowCount(); i++)
                {
                    int IdCC = (int) ChefChantier.recupererIdCCST(jTableST, i);
                    ChefChantier.recupererIdCCST(jTableST, i);
                    PreparedStatement ps = connexionSousTraitant2.getConnexion().prepareStatement("" +
                            "SELECT FonctionCC, NomCC, PrenomCC " +
                            "FROM ChefChantier " +
                            "WHERE IdCC = ?;");
                    ps.setInt(1, IdCC);
                    resultats = ps.executeQuery();
                    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);
                        WritableCellFormat format = new WritableCellFormat (font);
                        format.setAlignment(Alignment.CENTRE);
                        format.setBorder(Border.ALL, BorderLineStyle.THIN);
                        sheet.insertRow(39);
                        Label label26 = new Label(0, 39, "",format12);
                        sheet.addCell(label26);
                        sheet.mergeCells(1, 39, 3, 39);
                        sheet.mergeCells(4, 39, 5, 39);
                        Label label1 = new Label(1, 39 ,nomST, format);
                        Label label2 = new Label(4, 39 ,nomCCST, format);
                        Label label3 = new Label(6, 39 ,fonctionCCST, format);
                        Label label4 = new Label(7, 39 ,telCCST, format);
                        sheet.addCell(label1);
                        sheet.addCell(label2);
                        sheet.addCell(label3);
                        sheet.addCell(label4);
                    }
                    resultats.close();
                }
                connexionSousTraitant2.closeConn();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    Et sur connexionCoordonneesST :
    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
     
        /* Récupérer les coordonnées des sous-traitant */
        public void coordonneesST(JTable jTableST) throws SQLException, WriteException
        {
            try{
                Connexion connexionCoordonneesST = new Connexion();
                ResultSet resultats = null;
     
                WritableFont font = new WritableFont(WritableFont.ARIAL, 10);
                WritableCellFormat format12 = new WritableCellFormat (font);
                format12.setAlignment(Alignment.CENTRE);
                format12.setBorder(Border.LEFT, BorderLineStyle.THIN);
                ArrayList sousTraitant = new ArrayList();
                ArrayList nomSociete = new ArrayList();
                for(int m = 0;m < jTableST.getRowCount(); m++)
                {
                    nomSociete.add(jTableST.getValueAt(m, 0));
                }
                for(int j = 0;j<nomSociete.size();j++)
                {
                    try{
                        String NomSociete = (String) nomSociete.get(j);
                        PreparedStatement ps = connexionCoordonneesST.getConnexion().prepareStatement("" +
                            "SELECT NumRue, NomRue, CodePostal, Ville, Tel, Fax, Mail " +
                            "FROM Societe " +
                            "WHERE NomSociete = ?;");
                        ps.setString(1, NomSociete);
                        resultats = ps.executeQuery();
                        while(resultats.next())
                        {
                            sousTraitant.add(nomSociete.get(j).toString()+"  "+resultats.getString(1)+" "+resultats.getString(2)+" "+resultats.getString(3)+" "+resultats.getString(4)+" - "+resultats.getString(5)+"  "+resultats.getString(6)+"  "+resultats.getString(7));
                        }
                        resultats.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                for(int k=0; k<sousTraitant.size(); k++)
                {
                    sheet.insertRow(16);
                    Label label27 = new Label(0, 16 , "", format12);
                    sheet.mergeCells(1, 16, 7, 16);
                    WritableCellFormat format = new WritableCellFormat (font);
                    format.setAlignment(Alignment.CENTRE);
                    format.setBorder(Border.ALL, BorderLineStyle.THIN);
                    Label label = new Label(1, 16 ,sousTraitant.get(k).toString(), format);
                    sheet.addCell(label);
                    sheet.addCell(label27);
                }
                connexionCoordonneesST.closeConn();
            } catch (Exception e) {
                e.printStackTrace();
            }        
        }
    Le tout est dans le même fichier : FichierExcel.java !

  16. #336
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    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 713
    Points : 4 792
    Points
    4 792
    Par défaut
    Je crois que j'ai compris.
    Le code suivant est dans une boucle
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    PreparedStatement ps    = connexionSousTraitant.getConnexion().prepareStatement("" + ...
    donc la création de l'objet Connection avec connexionSousTraitant.getConnexion() se fait plusieurs fois
    et au moment de la fermeture ça doit être le binz !

    Essaye :
    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
        /* 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 connexionSousTraitant = new Connexion();
            Connection maConnectionUtilisablePlusieursFois = connexionSousTraitant.getConnexion();
            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);
                int idChefChantier = (int) ChefChantier.recupererIdCCST(jTableST, i);
                PreparedStatement ps    = maConnectionUtilisablePlusieursFois.prepareStatement("" +
                        "SELECT FonctionCC, NomCC, PrenomCC " +
                        "FROM ChefChantier " +
                        "WHERE IdCC = ?;");
                ps.setInt(1, idChefChantier);
                resultats = ps.executeQuery();
                while(resultats.next())
                {
         ...
                }
                resultats.close();
            }
            connexionSousTraitant.closeConn();
        }

  17. #337
    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
    Totalement fonctionnel pour la première erreur !!!
    J'ai donc appliqué le correctif sur les autres et c'est tout aussi fonctionnel

    Ah si les gens aussi serviables que vous n'existaient pas... Merci

    Par contre pour mes tableaux, je n'ai plus de soucis avec les societes mais pour les charge d'affaire c'est le même "binz".
    pourtant j'ai appliqué le même principe (appelle de afficheCharge après chaque manipulation).
    Mais ce qui est étonnant, c'est que je fais un ORDER BY nomCharge dès le début et il n'est pas appliqué.
    Comment je le sais ? ==> je clique sur la colonne nomCharge et il me remonte des noms de chargé qui n'étaient pas là...

  18. #338
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Avant de fermer une connexion, on doit d'abord s'assurer qu'elle n'est pas null.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     if(con !=null)
    try {
                 con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
    Des lignes ne servent à rien dans la méthode getConnection().

    A+.

  19. #339
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 713
    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 713
    Points : 4 792
    Points
    4 792
    Par défaut
    Citation Envoyé par Spiicky Voir le message
    Mais ce qui est étonnant, c'est que je fais un ORDER BY nomCharge dès le début et il n'est pas appliqué.
    Comment je le sais ? ==> je clique sur la colonne nomCharge et il me remonte des noms de chargé qui n'étaient pas là...
    tu n'aurais pas un setRowSorter ou un setAutoCreateRowSorter quelque part sur ce tableau ?

  20. #340
    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
    Tout à fait, j'ai setAutoCreateRowSorter mais ce sont des données grisées...
    Je pense que c'est généré par l'application. Je peux y accéder via le coté design ?

    Je suis désemparé voire même désespéré
    Je vais encore devoir faire un genre de patch pour mettre l'ancienne appli à jour vers celle ci et j'ignore complètement comment faire

+ 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