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

avec Java Discussion :

Problème de requête SQL


Sujet :

avec Java

  1. #21
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Merci mais il n'y a plus d'erreur le seul problème que j'ai c'est que le résultat de la requête n'est pas bon. Si dans ma table de ma BDD il y a deux films avec une même date de sortie mais une clé primaire différentes, la requête devrait m'afficher c'est derniers mais la requête ne m'en affiche que un, savez-vous pourquoi ?

    Cordialement et merci encore OButterlin !

  2. #22
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    euh non, il faudrait mettre le programme en debug et voir ce qui ce passe dans la boucle
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #23
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Comment fait-on pour faire le debug ? (clic droit debug file ? SI c'est ca je viens de le faire mais rien ne se passe..)

    Cordialement

  4. #24
    Modérateur

    Avatar de Robin56
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juin 2009
    Messages
    5 297
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Juin 2009
    Messages : 5 297
    Par défaut
    Citation Envoyé par Ercan67000 Voir le message
    Comment fait-on pour faire le debug ? (clic droit debug file ? SI c'est ca je viens de le faire mais rien ne se passe..)
    C'est comme le lancement normal d'un programme mais en mode Debug (l'icône à côté) : ici
    Responsable Java de Developpez.com (Twitter et Facebook)
    Besoin d'un article/tutoriel/cours sur Java, consulter la page cours
    N'hésitez pas à consulter la FAQ Java et à poser vos questions sur les forums d'entraide Java
    --------
    Architecte Solution
    LinkedIn : https://www.linkedin.com/in/nicolascaudard/

  5. #25
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Je viens de faire un debug merci, mais je ne comprend pas je rentre bien dans la boucle while (rs.next()) là, je fais un passage dedans puis à la fin de la boucle normalement le curseur doit refaire un passage mais il remonte directement sur la ligne while (rs.next()) et redescend tout de suite après le catch sans même repasser dans le while. Il fait un passage c'est tout..

    Cordialement et merci de votre aide !

  6. #26
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Et bien c'est que ta requête ne renvoie effectivement qu'un seul enregistrement.
    Tu as un outils avec ta base de données qui permet de tester la requête directement ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  7. #27
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Merci de votre aide, mais comment cela se fait-il ? Vu que la requête doit sélectionner tous les enregistrements ayant comme date la date saisie dans le jTextField non ? Pourquoi s'arrête-t-elle dès qu'un enregistrement est trouvé et pourquoi ne continue-t-elle pas après cet enregistrement ?
    Non je n'ai pas d'outils je travail avec mysql sou wamp server..

    Cordialement et merci OButterlin !

  8. #28
    Modérateur

    Avatar de Robin56
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juin 2009
    Messages
    5 297
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Juin 2009
    Messages : 5 297
    Par défaut
    Citation Envoyé par Ercan67000 Voir le message
    Non je n'ai pas d'outils je travail avec mysql sou wamp server..
    Je te conseille d'en procurer un ou même de tester tes requêtes sous l'invite DOS de ton MySQL (mais c'est plus galère). Ça te permet de cerner quand tes problèmes viennent de tes requêtes ou de ton code?
    Responsable Java de Developpez.com (Twitter et Facebook)
    Besoin d'un article/tutoriel/cours sur Java, consulter la page cours
    N'hésitez pas à consulter la FAQ Java et à poser vos questions sur les forums d'entraide Java
    --------
    Architecte Solution
    LinkedIn : https://www.linkedin.com/in/nicolascaudard/

  9. #29
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Merci, je pense plus que l'erreur vient de mon code vu que dans la requête je viens d'effectuer un count(*) pour voir combien de ligne avec cette date il me trouve et il m'en trouve bien deux dans ma BDD mais à l'affichage que un..

    Cordialement

  10. #30
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    je viens de mettre ton code dans un éditeur un peu plus sympa pour mieux comprendre.
    tu as une erreur grossière, tu fais plusieurs fois des accès aux mêmes colonnes (rs.getString(2), etc...)
    il faut en début de boucle récupérer tes valeurs et ensuite les utiliser
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    while (rs.next())
    {
       String col1 = rs.getString(1);
       String col2 = rs.getString(2);
       ...
       paragraph = new Paragraph(col2, new Font(Font.BOLD, 14, Font.BOLD, Color.BLACK));
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  11. #31
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Merci, je viens d'effectuer ces changements mais j'ai toujours le même résultat..

    Cordialement

  12. #32
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    fait voir le code actuel
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  13. #33
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Mon code a été modifié le voici :
    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
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
     
            try {
                PdfWriter.getInstance(document, new FileOutputStream("Test.pdf"));
     
                document.open();
     
                Chunk chunk = new Chunk("Synthèse",
                        FontFactory.getFont(FontFactory.COURIER, 18, Font.NORMAL, Color.WHITE));
                chunk.setBackground(Color.GRAY);
                document.add(chunk);
     
                //Tableau 1
                Table tableau = new Table(3, 2);
                tableau.setBorderColor(Color.white);
                tableau.setPadding(3);
                tableau.setWidth(100);
     
                //Tableau 2
                Table tableau1 = new Table(3, 3);
                tableau1.setBorderColor(Color.white);
                tableau1.setPadding(3);
                tableau1.setWidth(100);
     
                try {
                    stmt = (PreparedStatement) con.prepareStatement("SELECT No, Date, Heure, Resume, Obs, Ville, Pays, Details, id_auteurs, COUNT(*) as N1 FROM t_films WHERE Date = ?");
                    stmt.setDate(1, maDateSQL);
                    rs = stmt.executeQuery();
     
                    while (rs.next()) {
     
                        String col1 = rs.getString(1);
                        Date col2 = rs.getDate(2);
                        //col2 = formatter.format(maDateJava);
                        String col3 = rs.getString(3);
                        String col4 = rs.getString(4);
                        String col5 = rs.getString(5);
                        String col6 = rs.getString(6);
                        String col7 = rs.getString(7);
                        String col8 = rs.getString(8);
                        String id = rs.getString(9);
     
                        //JOUR
                        String datePdf = DateFormat.getDateInstance().format(col2);
                        paragraph = new Paragraph(datePdf,
                                new Font(Font.BOLD, 14, Font.BOLD, Color.BLACK));
                        paragraph.setIndentationLeft(210f);
                        document.add(paragraph);
     
                        paragraph = new Paragraph("Ce jour-là " + rs.getInt("N1") + " films ont été enregistrés",
                                new Font(Font.NORMAL, 10, Font.NORMAL, Color.BLACK));
                        paragraph.setIndentationLeft(120f);
                        document.add(paragraph);
     
                        paragraph = new Paragraph("___________________________________________________________________________",
                                new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK));
                        paragraph.setIndentationRight(10f);
                        paragraph.setIndentationLeft(10f);
                        document.add(paragraph);
     
                        //Tableau 1
                        cell = new Cell(new Paragraph("Heure : " + col3,
                                new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.white);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        tableau.addCell(cell);
     
                        cell = new Cell("");
                        cell.setBorderColor(Color.white);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tableau.addCell(cell);
     
                        cell = new Cell(new Paragraph("N° : " + col1,
                                new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.white);
                        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        tableau.addCell(cell);
     
                        cell = new Cell(new Paragraph(col7,
                                new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.black);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        tableau.addCell(cell);
     
                        cell = new Cell(new Paragraph(col6,
                                new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.black);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tableau.addCell(cell);
     
                        cell = new Cell(new Paragraph(col6,
                                new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.black);
                        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        tableau.addCell(cell);
     
                        document.add(tableau);
                        document.add(Chunk.NEWLINE);
     
     
                        paragraph = new Paragraph(col4,
                                new Font(Font.BOLD, 11, Font.BOLD, Color.BLACK));
                        paragraph.setIndentationRight(20f);
                        document.add(paragraph);
     
                        paragraph = new Paragraph(col5,
                                new Font(Font.NORMAL, 11, Font.BOLD, Color.BLACK));
                        paragraph.setIndentationLeft(20f);
                        document.add(paragraph);
                        paragraph = new Paragraph(col8,
                                new Font(Font.NORMAL, 11, Font.NORMAL, Color.BLACK));
                        paragraph.setIndentationRight(20f);
                        document.add(paragraph);
     
     
                        try {
                            stmt = (PreparedStatement) con.prepareStatement("SELECT NomPersonne, Sexe, Age, Deplacement, Aide, Veh, Observation, Role, PersResp FROM t_auteurs WHERE id_a = ?");
                            stmt.setString(1, id);
                            rs = stmt.executeQuery();
                            while (rs.next()) {
                                String colonne1 = rs.getString(1);
                                String colonne2 = rs.getString(2);
                                String colonne3 = rs.getString(3);
                                String colonne4 = rs.getString(4);
                                String colonne5 = rs.getString(5);
                                String colonne6 = rs.getString(6);
                                String colonne7 = rs.getString(7);
                                String colonne8 = rs.getString(8);
                                String colonne9 = rs.getString(9);
     
                                //Tableau 2
                                tableau1 = new Table(3, 3);
                                tableau1.setBorderColor(Color.white);
                                tableau1.setPadding(3);
                                tableau1.setWidth(100);
                                //Tableau 3
                                Table tableau2 = new Table(1, 1);
                                tableau2.setPadding(1);
                                tableau2.setWidth(14);
     
                                paragraph = new Paragraph(".........................................."
                                        + "....................................",
                                        new Font(Font.NORMAL, 10, Font.BOLD, Color.BLACK));
                                paragraph.setIndentationRight(20f);
                                paragraph.setIndentationLeft(20f);
                                document.add(paragraph);
     
                                cell = new Cell(new Paragraph(colonne6,
                                        new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                                cell.setBorderColor(Color.black);
                                cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
                                tableau2.addCell(cell);
                                document.add(tableau2);
     
                                //Tableau 2
                                cell = new Cell(new Paragraph(colonne2 + "    agé(e) de " + colonne3,
                                        new Font(Font.BOLD, 11, Font.ITALIC, Color.BLACK)));
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell(new Paragraph(colonne1,
                                        new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                                tableau1.addCell(cell);
     
                                cell = new Cell(new Paragraph(colonne5,
                                        new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                                tableau1.addCell(cell);
     
                                cell = new Cell(colonne6 + "   " + colonne8);
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell(new Paragraph(colonne4,
                                        new Font(Font.BOLD, 11, Font.ITALIC, Color.BLACK)));
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell("");
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                                tableau1.addCell(cell);
     
                                cell = new Cell("");
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell(colonne7);
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell("Personne responsable : " + colonne9);
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                                tableau1.addCell(cell);
     
                                document.add(tableau1);
     
                            }
                        } catch (Exception e) {
                            System.out.println("Erreur");
                        }
                    }
                } catch (Exception e) {
                    System.out.println("Erreur");
                }
            } catch (Exception e) {
            }
            document.close();
    Excusez-moi du dérangement encore !

    Cordialement et merci pour votre aide !

  14. #34
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    bon ben là c'est clair, tu ne peux pas utiliser le même stmt dans une boucle impriquée !
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  15. #35
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Merci de votre aide, je viens de renommer le deuxième stmt mais cela ne change rien.. Savez-vous pourquoi ?

    Cordialement et bonne journée !

  16. #36
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    il ne s'agit pas que du statement, il faut également un autre ResultSet, y as-tu pensé ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  17. #37
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Je viens de changer le ResultatSet aussi mais ça ne change toyujours rien..
    Voici l'extrait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
                        try {
                            stmt1 = (PreparedStatement) con.prepareStatement("SELECT NomPersonne, Sexe, Age, Deplacement, Ble, Veh, Observation, Role, PersResp FROM personnes WHERE RefA = ?");
                            stmt1.setString(1, id);
                            rs1 = stmt1.executeQuery();
                            while (rs1.next()) {
                                String colonne1 = rs1.getString(1);
                                String colonne2 = rs1.getString(2);
                                String colonne3 = rs1.getString(3);
                                String colonne4 = rs1.getString(4);
                                String colonne5 = rs1.getString(5);
                                String colonne6 = rs1.getString(6);
                                String colonne7 = rs1.getString(7);
                                String colonne8 = rs1.getString(8);
                                String colonne9 = rs1.getString(9);

  18. #38
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Mets ton code en entier à chaque fois, là, on ne voit rien
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  19. #39
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2011
    Messages : 124
    Par défaut
    Excusez-moi.
    Voici mon code :
    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
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
     
            try {
                PdfWriter.getInstance(document, new FileOutputStream("Test.pdf"));
     
                document.open();
     
                Chunk chunk = new Chunk("Synthèse",
                        FontFactory.getFont(FontFactory.COURIER, 18, Font.NORMAL, Color.WHITE));
                chunk.setBackground(Color.GRAY);
                document.add(chunk);
     
                //Tableau 1
                Table tableau = new Table(3, 2);
                tableau.setBorderColor(Color.white);
                tableau.setPadding(3);
                tableau.setWidth(100);
     
                //Tableau 2
                Table tableau1 = new Table(3, 3);
                tableau1.setBorderColor(Color.white);
                tableau1.setPadding(3);
                tableau1.setWidth(100);
     
                try {
                    stmt = (PreparedStatement) con.prepareStatement("SELECT No, Date, Heure, Resume, Obs, Ville, Pays, Details, id_auteurs, COUNT(*) as N1 FROM t_films WHERE Date = ?");
                    stmt.setDate(1, maDateSQL);
                    rs = stmt.executeQuery();
     
                    while (rs.next()) {
     
                        String col1 = rs.getString(1);
                        Date col2 = rs.getDate(2);
                        //col2 = formatter.format(maDateJava);
                        String col3 = rs.getString(3);
                        String col4 = rs.getString(4);
                        String col5 = rs.getString(5);
                        String col6 = rs.getString(6);
                        String col7 = rs.getString(7);
                        String col8 = rs.getString(8);
                        String id = rs.getString(9);
     
                        //JOUR
                        String datePdf = DateFormat.getDateInstance().format(col2);
                        paragraph = new Paragraph(datePdf,
                                new Font(Font.BOLD, 14, Font.BOLD, Color.BLACK));
                        paragraph.setIndentationLeft(210f);
                        document.add(paragraph);
     
                        paragraph = new Paragraph("Ce jour-là " + rs.getInt("N1") + " films ont été enregistrés",
                                new Font(Font.NORMAL, 10, Font.NORMAL, Color.BLACK));
                        paragraph.setIndentationLeft(120f);
                        document.add(paragraph);
     
                        paragraph = new Paragraph("___________________________________________________________________________",
                                new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK));
                        paragraph.setIndentationRight(10f);
                        paragraph.setIndentationLeft(10f);
                        document.add(paragraph);
     
                        //Tableau 1
                        cell = new Cell(new Paragraph("Heure : " + col3,
                                new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.white);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        tableau.addCell(cell);
     
                        cell = new Cell("");
                        cell.setBorderColor(Color.white);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tableau.addCell(cell);
     
                        cell = new Cell(new Paragraph("N° : " + col1,
                                new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.white);
                        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        tableau.addCell(cell);
     
                        cell = new Cell(new Paragraph(col7,
                                new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.black);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        tableau.addCell(cell);
     
                        cell = new Cell(new Paragraph(col6,
                                new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.black);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        tableau.addCell(cell);
     
                        cell = new Cell(new Paragraph(col6,
                                new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
                        cell.setBorderColor(Color.black);
                        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        tableau.addCell(cell);
     
                        document.add(tableau);
                        document.add(Chunk.NEWLINE);
     
     
                        paragraph = new Paragraph(col4,
                                new Font(Font.BOLD, 11, Font.BOLD, Color.BLACK));
                        paragraph.setIndentationRight(20f);
                        document.add(paragraph);
     
                        paragraph = new Paragraph(col5,
                                new Font(Font.NORMAL, 11, Font.BOLD, Color.BLACK));
                        paragraph.setIndentationLeft(20f);
                        document.add(paragraph);
                        paragraph = new Paragraph(col8,
                                new Font(Font.NORMAL, 11, Font.NORMAL, Color.BLACK));
                        paragraph.setIndentationRight(20f);
                        document.add(paragraph);
     
     
                        try {
                            stmt1 = (PreparedStatement) con.prepareStatement("SELECT NomPersonne, Sexe, Age, Deplacement, Aide, Veh, Observation, Role, PersResp FROM t_auteurs WHERE id_a = ?");
                            stmt1.setString(1, id);
                            rs1 = stmt1.executeQuery();
                            while (rs1.next()) {
                                String colonne1 = rs1.getString(1);
                                String colonne2 = rs1.getString(2);
                                String colonne3 = rs1.getString(3);
                                String colonne4 = rs1.getString(4);
                                String colonne5 = rs1.getString(5);
                                String colonne6 = rs1.getString(6);
                                String colonne7 = rs1.getString(7);
                                String colonne8 = rs1.getString(8);
                                String colonne9 = rs1.getString(9);
     
                                //Tableau 2
                                tableau1 = new Table(3, 3);
                                tableau1.setBorderColor(Color.white);
                                tableau1.setPadding(3);
                                tableau1.setWidth(100);
                                //Tableau 3
                                Table tableau2 = new Table(1, 1);
                                tableau2.setPadding(1);
                                tableau2.setWidth(14);
     
                                paragraph = new Paragraph(".........................................."
                                        + "....................................",
                                        new Font(Font.NORMAL, 10, Font.BOLD, Color.BLACK));
                                paragraph.setIndentationRight(20f);
                                paragraph.setIndentationLeft(20f);
                                document.add(paragraph);
     
                                cell = new Cell(new Paragraph(colonne6,
                                        new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                                cell.setBorderColor(Color.black);
                                cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
                                tableau2.addCell(cell);
                                document.add(tableau2);
     
                                //Tableau 2
                                cell = new Cell(new Paragraph(colonne2 + "    agé(e) de " + colonne3,
                                        new Font(Font.BOLD, 11, Font.ITALIC, Color.BLACK)));
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell(new Paragraph(colonne1,
                                        new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                                tableau1.addCell(cell);
     
                                cell = new Cell(new Paragraph(colonne5,
                                        new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                                tableau1.addCell(cell);
     
                                cell = new Cell(colonne6 + "   " + colonne8);
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell(new Paragraph(colonne4,
                                        new Font(Font.BOLD, 11, Font.ITALIC, Color.BLACK)));
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell("");
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                                tableau1.addCell(cell);
     
                                cell = new Cell("");
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell(colonne7);
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                tableau1.addCell(cell);
     
                                cell = new Cell("Personne responsable : " + colonne9);
                                cell.setBorderColor(Color.white);
                                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                                tableau1.addCell(cell);
     
                                document.add(tableau1);
     
                            }
                        } catch (Exception e) {
                            System.out.println("Erreur");
                        }
                    }
                } catch (Exception e) {
                    System.out.println("Erreur");
                }
            } catch (Exception e) {
            }
            document.close();

  20. #40
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    je ne sais pas, passe ton programme en debug et regarde pour où il passe...
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

Discussions similaires

  1. Problème de requête SQL avec instruction TRANSFORM
    Par Nosper dans le forum Requêtes et SQL.
    Réponses: 4
    Dernier message: 21/06/2005, 16h15
  2. problème de requète SQL pour formulaire
    Par en_stage dans le forum Requêtes et SQL.
    Réponses: 15
    Dernier message: 21/06/2005, 12h21
  3. [SQL] Problème de requête SQL de plus de 8060 caractères ?
    Par webtheque dans le forum MS SQL Server
    Réponses: 13
    Dernier message: 06/04/2005, 15h07
  4. [SQLserver2000][SQLServer CE] problème de requête SQL
    Par JBernn dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 27/01/2005, 09h29
  5. Problème de requète SQL dans un Requery
    Par Keraccess dans le forum Requêtes et SQL.
    Réponses: 7
    Dernier message: 22/10/2004, 14h58

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