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

Langage Java Discussion :

Problème boucle while


Sujet :

Langage Java

  1. #1
    Membre du Club
    Inscrit en
    Novembre 2003
    Messages
    84
    Détails du profil
    Informations forums :
    Inscription : Novembre 2003
    Messages : 84
    Points : 58
    Points
    58
    Par défaut Problème boucle while
    Bonjour voici mon pb
    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
     
    while((line = buff.readLine()) != null){
    							String entete = line.substring(0,5);
    							if(entete.equals("RFF10")){
    								tag = 1;
    								ref = "";
    								ref = line.substring(8,line.length());								
    								if(ref.trim().length()<= 6){//recuperation du n° de cde minos
    									while(ref.trim().length()<9){
    										ref = '0'+ref;
    									}
    									st = BaseDonnees.connexionAS400().prepareStatement("select vm010p10.nucmdc,vm010p10.clil,vm010p10.nuliv,vm007p10.rsclt,un100p10.livpoidst,un100p10.livinstr1,un100p10.dtcreenr,un100p10.indcde from vm010p10, vm007p10, un100p10 " +
    											"where vm007p10.cli = vm010p10.clil " +
    											"and un100p10.blnum = vm010p10.nuliv " +
    											"and vm010p10.cste='CRP' and vm010p10.nucmdc='"+ref+"' and vm010p10.nuliv<>''");
    									rs = st.executeQuery();
    									while (rs.next()){											
    										int j = rs.getRow();
    										if(j == 1){
    											if(rs.getString("rsclt").trim()!= ""){//raison sociale du client
    												cli = rs.getString("rsclt").trim();
    												System.out.println("cli: "+cli);
    											}else{
    												cli = "incon";
    											}
    											if(rs.getString("livpoidst").trim() != ""){//poids envoi
    												pds = rs.getString("livpoidst").trim().substring(0, 4);
    												pds = "0"+pds;
    												System.out.println("pds: "+pds);
    											}else{
    												pds = "0";
    											}
    											if(rs.getString("livinstr1").trim() != ""){
    												col = rs.getString("livinstr1").trim().substring(0, 2);//nb colis
    												pal = rs.getString("livinstr1").trim().substring(6, 8);//nb palettes
    												cp = col +"C"+"/"+pal+"P";
    												System.out.println("cp: "+cp);
    											}
    											if(rs.getString("clil").trim() != ""){//code client minos
    												clil = rs.getString("clil").trim();
    												System.out.println("clicode: "+clil);
    											}
    											if(rs.getString("dtcreenr").trim() != ""){//date d'enregistrement
    												aenv = rs.getString("dtcreenr").trim().substring(0, 4);
    												menv = rs.getString("dtcreenr").trim().substring(4, 6);
    												jenv = rs.getString("dtcreenr").trim().substring(6, rs.getString("dtcreenr").trim().length());
    												System.out.println("date: "+aenv+"/"+menv+"/"+jenv);
    											}else{
    												aenv = "00";
    												menv = "00";
    												jenv = "00";
    											}
    											if(rs.getString("indcde").trim() != ""){
    												ind = rs.getString("indcde").trim();
    												System.out.println("ind:"+ind);
    											}else{
    												ind = "000";
    											}
    											refc = "inconnu";
    										}
    									}
    								}
    								if(ref.trim().length() > 9){//recup n° de bl dans la ligne si pas de n° de cde									
    									k = line.substring(26, 29);
    									if(k.equals("KAF")){
    										ref = "incon";
    										refc = line.substring(29, 37);
    										clil = "incon";
    										cli = "incon";
    									}
    									if((k.equals("KMS")) || (k.equals("KSX"))){
    										bl = line.substring(29, 37);
    										while(bl.length() < 9){
    											bl = "0"+bl;
    										}
    										st1 = BaseDonnees.connexionAS400().prepareStatement("select vm010p10.nucmdc,vm010p10.clil,vm010p10.nuliv,vm007p10.rsclt,un100p10.livpoidst,un100p10.livinstr1,un100p10.dtcreenr,un100p10.indcde from vm010p10, vm007p10, un100p10 " +
    												"where vm007p10.cli = vm010p10.clil " +
    												"and un100p10.blnum = vm010p10.nuliv " +
    												"and vm010p10.cste='CRP' and vm010p10.nuliv='"+bl+"'");
    										rs1 = st1.executeQuery();
    										while (rs.next()){
    											int j = rs.getRow();
    											if(j == 1){
    												if(rs1.getString("rsclt").trim()!= ""){//raison sociale du client
    													cli = rs1.getString("rsclt").trim();
    												}else{
    													cli = "incon";
    												}
    												if(rs1.getString("livpoidst").trim() != ""){//poids envoi
    													pds = rs1.getString("livpoidst").trim().substring(0, 4);
    													pds = "0"+pds;
    												}else{
    													pds = "0";
    												}
    												if(rs1.getString("livinstr1").trim() != ""){
    													col = rs1.getString("livinstr1").trim().substring(0, 2);//nb colis
    													pal = rs1.getString("livinstr1").trim().substring(6, 8);//nb palettes
    													cp = col +"C"+"/"+pal+"P";
    												}
    												if(rs1.getString("clil").trim() != ""){//code client minos
    													clil = rs1.getString("clil").trim();
    												}
    												if(rs1.getString("nucmdc").trim() != ""){
    													ref = rs1.getString("nucmdc").trim();
    												}else{
    													ref= "incon";
    												}
    												if(rs1.getString("dtcreenr").trim() != ""){//date d'enregistrement
    													aenv = rs1.getString("dtcreenr").trim().substring(0, 4);
    													menv = rs1.getString("dtcreenr").trim().substring(4, 6);
    													jenv = rs1.getString("dtcreenr").trim().substring(6, rs1.getString("dtcreenr").trim().length());
    												}else{
    													aenv = "00";
    													menv = "00";
    													jenv = "00";
    												}
    												if(rs1.getString("indcde").trim() != ""){
    													ind = rs1.getString("indcde").trim();
    												}else{
    													ind = "000";
    												}
    												if(rs1.getString("nucmdc").trim() != ""){
    													ref = rs1.getString("nucmdc").trim();
    												}else{
    													ref = "incon";
    												}
    											}
    										}
    									}
    								}
    							}
    							if(entete.equals("RSJ20")){//suivi d'expedition
    								tag = 2;
    								sit = line.substring(8, 11);
    								st1 = BaseDonnees.connexionPostgres().prepareStatement("select libelle from codsit where code='"+sit+"'");
    								rs1 = st1.executeQuery();
    								while(rs1.next()){
    									sit = rs1.getString("libelle").trim();//libelle situation
    									System.out.println("sit: "+sit);
    								}
    								just = line.substring(11, 14);
    								st1 = BaseDonnees.connexionPostgres().prepareStatement("select libelle from codjust where code='"+just+"'");
    								rs1 = st1.executeQuery();
    								while(rs1.next()){
    									just = rs1.getString("libelle").trim();//libelle justification
    									System.out.println("just: "+just);
    								}
    							} 
    							if(entete.equals("DTM30")){//date operation chez transporteur
    								dtm = line.substring(5, 8);
    								if(dtm.equals("DSJ")){
    									tag = 3;
    									dtm1 = "20"+line.substring(8, 14);
    									h = line.substring(14, line.length());
    									System.out.println("date et heure: "+dtm1+" "+h);
    								}								
    							}
    							if(entete.equals("TXT30")){//marquage colis et n° de recepisse
    								txt = line.substring(5, 8);
    								if(txt.equals("RCO")){
    									tag = 4;
    									pci = line.substring(29, line.length());
    									System.out.println("marquage: "+pci);
    								}
    								if(txt.equals("DEL")){//ligne de commentaire
    									tag = 5;
    									del = line.substring(8, line.length());
    									System.out.println("com;: "+del);
    								}								
    							}
    							if(tag == 5){
    								InsertBase insert = new InsertBase();
    								System.out.println(transp+" "+pci+" "+clil+" "+cli+" "+ref+" "+ind+" "+refc+" "+sit+" "+just+" "+dtm1+" "+h+" "+del+" "+cp+" "+pds+" "+aenv+" "+menv+" "+jenv);
    								insert.insertB(transp, pci, clil, cli, ref, ind, refc, sit, just, dtm1, h, del, cp, pds, aenv, menv, jenv);						
    							}
    						}
    						}finally{
    							buff.close();
    						}
    le souci c'est que ma derniere condition if me fait sortir de ma boucle, par contre si je l'enleve je boucle bien.
    je ne comprends pas alors si quelqu'un pouvait m'eclairer ce ,serait super
    Merci

  2. #2
    Membre averti Avatar de Tux++
    Étudiant
    Inscrit en
    Avril 2008
    Messages
    281
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2008
    Messages : 281
    Points : 379
    Points
    379
    Par défaut
    Bonsoir,


    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 72, Size: 72
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)


    IndexOutOfBounds, comme son nom l'indique est une exception qui signale que tu dépasses l'indice max d'un tableau.

    Exemple: ici ton tabelau à une taille 72 (fin ton ArrayList) et l'exception signale que tu essayes d'atteindre la case 72, qui n'existe pas, vu qu'un Arraylist de taille 72 est accessible de 0 à 71 donc cela provient sûrement d'un <= au lieu d'un < ou quelque chose comme ça


    autre remarque, tu mets beaucoup trop de while() et if() imbriqués, on ne s'y retrouve pas, divise en méthodes, en modules...utilse switch,...etc
    Certified Oracle Advanced PL/SQL Professional
    Certified Oracle APEX Expert
    Certified Oracle SQL Expert

  3. #3
    Membre du Club
    Inscrit en
    Novembre 2003
    Messages
    84
    Détails du profil
    Informations forums :
    Inscription : Novembre 2003
    Messages : 84
    Points : 58
    Points
    58
    Par défaut re
    Bon c'est sur mon code n'est pas tres clair, donc j'explique un peu
    je lis un fichier ligne par ligne et j'ai besoin d'extraire certaines donnees dans certaines lignes c'est pour ca que je dois tester l'entete de ligne pour determiner quel type d'info je recupere. Au final je dois inserer ces donnes dans ma base postgres.Tous mes if me servent a tester l'entete de ma ligne.
    le tag lui me sert a lancer le insert dans ma base.
    C'est pas du tout de l'optimiation mais bon je debute en java(pas en prog), j'optimiserais avec le temps.
    je ne comprends pas bien cet histoire de array.Mon souci est que quand le curseur arrive sur le if(tag == 5), parceque je ne veux lancer l'insert que quand il aura recupere toutes les infos, si ce n'est pas le cas il sort de ma boucle while
    si j'enleve cette condition ma boucle s'effectue normalement.
    Voila
    Merci

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

Discussions similaires

  1. problème boucle while
    Par Stephub dans le forum Débuter
    Réponses: 6
    Dernier message: 21/01/2009, 00h31
  2. Problème boucle while
    Par Peedro dans le forum Langage
    Réponses: 4
    Dernier message: 07/10/2008, 15h09
  3. Problème boucle while
    Par chuko dans le forum C
    Réponses: 7
    Dernier message: 04/07/2008, 17h12
  4. [MySQL] Problème boucle WHILE
    Par Adlack dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 26/02/2007, 20h30
  5. Problème boucle while et evenement
    Par tse_tilky_moje_imja dans le forum Général Python
    Réponses: 2
    Dernier message: 30/03/2006, 19h11

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