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 :

Insertions successives dans la base oracle


Sujet :

JDBC Java

  1. #1
    Membre du Club
    Inscrit en
    Mai 2008
    Messages
    112
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 112
    Points : 42
    Points
    42
    Par défaut Insertions successives dans la base oracle
    Salut tout le monde,
    Je travaille avec une base de donnée oracle 9i et mon programme (Jdeveloper)
    contient plusieurs acces a la base de données.Je fais plusieurs insertions dans différantes tables.j'ai utilisé le prepareStatement a plusieurs reprises mais des que j'execute la requete le programme se plante.Existe t-il un moyen qui permet d'inserer dans la base sans causer trop de complications et en améliorant le temps de reponse du programme

  2. #2
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Salut,

    Citation Envoyé par FstDsi Voir le message
    mais des que j'execute la requete le programme se plante.
    C'est à dire ?

    a++

  3. #3
    in
    in est déconnecté
    Membre expérimenté Avatar de in
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    1 612
    Détails du profil
    Informations personnelles :
    Localisation : France, Finistère (Bretagne)

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 612
    Points : 1 718
    Points
    1 718
    Par défaut
    Citation Envoyé par FstDsi Voir le message
    le prepareStatement a plusieurs reprises mais des que j'execute la requete le programme se plante.
    C-a-d ? Si tu as un message d'erreur, il fait nous l'indiquer, on ne peut pas deviner ...

    Citation Envoyé par FstDsi Voir le message
    Existe t-il un moyen qui permet d'inserer dans la base sans causer trop de complications et en améliorant le temps de reponse du programme
    Tu peux utiliser le "batch" des preparedStatement, ça améliore pas mal les choses.
    Il faut également désactiver l'autocommit ...

    Bref, si tu ne nous montres rien, on ne peut pas grand chose pour toi à part se lancer dans des conjectures ... et franchement, on n'a pas que ça à faire ...

  4. #4
    Membre du Club
    Inscrit en
    Mai 2008
    Messages
    112
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 112
    Points : 42
    Points
    42
    Par défaut
    Désolé g t pas assez claire et je n'ai pas donné mon code paske il est relativement long.en faite le programme parcourt un fichier forms(oracle developer) et extrait plusieurs informations relativement a sa structure.donc le programme contient plusieurs boucles et a chaque boucle il insere dans une table.g'ai developée une classe connexion qui se connecte sur le shema (ok,ok) Le code est le suivant:
    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
     
    package data;
     
    import java.sql.*;
    import oracle.jdbc.*;
    import oracle.sql.*;
    import java.io.*;
     
    public class ConnexionBD 
    {
    public   Statement stmt=null; 
    public ResultSet curJava;
    public PreparedStatement spdecf=null,spcanvong=null, spgraph=null,spparam=null,spgraphong=null,sprec=null,spdecb=null,spdeci=null,spbloc=null,spitem=null,spcanv=null,sprel=null;
     
     
    public boolean connect(String base,String nom,String motpasse)
    {
         try 
         {
             DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());//Chargement d'un pilote JDBC Oracle
             Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:BD1", "ok","ok");//Création d'une connexion
             stmt = conn.createStatement();//Creation d'un etat de connexion objet destinee a  recevoir un ordre SQL
              //curJava = stmt.executeQuery("ta requête");
              spdecf=conn.prepareStatement("insert into declencheur_f values(?,?,?,?,?)");
             spparam=conn.prepareStatement("insert into parametre values(?,?,?,?)");
             spcanvong=conn.prepareStatement("insert into onglet_canvas values(?,?,?,?)");
             spgraph=conn.prepareStatement("insert into graphique values(?,?,?,?,?)");
             spgraphong=conn.prepareStatement("insert into graphique_onglet values(?,?,?,?,?,?)");
             sprec=conn.prepareStatement("insert into grenreg values(?,?,?,?,?)");
              spdecb=conn.prepareStatement("insert into declencheur_b values(?,?,?,?,?,?)");
              spdeci=conn.prepareStatement("insert into declencheur_i values(?,?,?,?,?,?,?)");
              spbloc=conn.prepareStatement("insert into Bloc values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
              sprel=conn.prepareStatement("insert into relation values(?,?,?,?,?,?,?)");
              spitem=conn.prepareStatement("insert into item values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
              spcanv=conn.prepareStatement("insert into canvas values(?,?,?,?,?,?,?,?,?)");
             return(true);
         } 
         catch (SQLException ex) 
         {
             return(false);
         }   
    }
    }

    puis j'ai developpée la mathode scan_module qui se charge du parcourt et de l'extraction des données tout en inserant dans la base
    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
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
     
            private void scan_module_form(String s) {
            FormModule frm = FormModule.open(s); 
            JOptionPane c = new JOptionPane();
            FileWriter fw;
          try{  
            fw = new FileWriter("D:\\structure.txt");
             col1=frm.getName();
          col2=frm.getAbsolutePath();
           col3=frm.getConsoleWindow();
           col4=frm.getFirstNavigationBlockName();
           col5=frm.getMenuModule();
     
            String requet1="insert into Form values('"+col1+"',"+"'"+col2+"','" +col3+"','"+col4+"','"+col5+"')"; 
        try{
            if(rt.connect("BD1","ok","ok")){
            System.out.println("connexion établie:niveau module");
            rt.stmt.executeUpdate(requet1);
             //rt.curJava = rt.stmt.executeUpdate(requet1);
            }
            else
            System.out.println("Echec Connexion niveau module");}
            catch (SQLException f) {
             if (f instanceof SQLException){
                if( f.getErrorCode()==1)
                JOptionPane.showMessageDialog(c,"Le module est déja scanné","Terminé",JOptionPane.INFORMATION_MESSAGE);
                else{
               System.out.println("*****module******SQL Error Code is:  " + ((SQLException)f).getErrorCode());
               System.out.println("*****module******SQL Message Code is: " + f.getMessage());
               System.out.println("*****module******SQL State is: " + ((SQLException)f).getSQLState());
                }
                }
                System.out.println("*****module******Insert failed. " + ((SQLException)f).getMessage());
                   return;
            }
     
     
     
     
                 //Recherche Des Canvas  Niveau Form
                   JdapiIterator Canvas = frm.getCanvases();
                   while (Canvas.hasNext())
                   {
                   Canvas canv = (Canvas)Canvas.next();
                  // insert_canvas(frm,canv);
                   String c1=canv.getName();
                   String c2=frm.getName();
                    String c3=frm.getAbsolutePath();
                    String c4=GetCanvType(canv.getCanvasType());
                    String c5=canv.getWindowName();
                   int x6=canv.getHeight();
                   int x7=canv.getWidth();
                    String c8=canv.getVisualAttributeName();
                    String c9="";
                   try{
                     if(rt.connect("BD1","ok","ok")){
                    System.out.println("connexion établie canvas");
                     rt.spcanv.setString(1,c1);
                    rt.spcanv.setString(2,c2);
                    rt.spcanv.setString(3,c3);
                    rt.spcanv.setString(4,c4);
                    rt.spcanv.setString(5,c5);
                    rt.spcanv.setInt(6,x6);
                     rt.spcanv.setInt(7,x7);
                    rt.spcanv.setString(8,c8);
                     rt.spcanv.setString(9,c9);
                    rt.spcanv.execute();
                }
                                                   else
                                                       System.out.println("Echec Connexion niveau canvas"); 
     
                                               }
                                               catch (SQLException f) {
     
                                                     if (f instanceof SQLException){
                                                 System.out.println("***canvas****SQL Error Code is:  " + ((SQLException)f).getErrorCode());
                                                 System.out.println("****canvas*****SQL Message Code is: " + f.getMessage());
                                                 System.out.println("****canvas****SQL State is: " + ((SQLException)f).getSQLState());
                                                 }
                                                 System.out.println("****canvas****Insert failed. " + ((SQLException)f).getMessage());
                                                 return;
                                                 }
     
     
     
                   JdapiIterator graphs= canv.getGraphicses();
                   JdapiIterator tab=canv.getTabPages();
                           if((canv.getCanvasType())==4){
                            while(tab.hasNext()){
                              TabPage sss=(TabPage)tab.next();
                               String ong1=sss.getName();
                               String ong2=canv.getName();
                               String ong3=frm.getName();
                               String ong4=frm.getAbsolutePath();
                               try{
                                                               if(rt.connect("BD1","ok","ok")){
     
                                                                   rt.spcanvong.setString(1,ong1);
                                                                   rt.spcanvong.setString(2,ong2);
                                                                   rt.spcanvong.setString(3,ong3);
                                                                   rt.spcanvong.setString(4,ong4);
                                                                   rt.spcanvong.execute();
     
                                                               }
                                                               else
                                                                   System.out.println("Echec Connexion niveau onglet_canvas"); 
     
                                                           }
                                                           catch (SQLException f) {
     
                                                                 if (f instanceof SQLException){
                                                             System.out.println("**onglet_canvas****SQL Error Code is:  " + ((SQLException)f).getErrorCode());
                                                             System.out.println("***onglet_canvas*****SQL Message Code is: " + f.getMessage());
                                                             System.out.println("****onglet_canvas****SQL State is: " + ((SQLException)f).getSQLState());
                                                             }
                                                             System.out.println("****onglet_canvas****Insert failed. " + ((SQLException)f).getMessage());
                                                             return;
                                                             }
     
     
     
                              //insert_canvas_onglet(sss,canv,frm);
                             // fw.write("\t**** sss.getname****:"+ sss.getName()+"\n"); 
                              JdapiIterator grahtab=sss.getGraphicses();
                              while(grahtab.hasNext()){
                                  Graphics xxx=(Graphics)grahtab.next();
                                  String   ongraph1=xxx.getName();
                                  String   ongraph2=sss.getName();
                                  String   ongraph3=canv.getName();
                                  String   ongraph4=frm.getName();
                                  String   ongraph5=frm.getAbsolutePath();
                                  String   ongraph6=GetGraphType(xxx.getGraphicsType());
                                  try{
                                                                  if(rt.connect("BD1","ok","ok")){
     
                                                                      rt.spgraphong.setString(1,ongraph1);
                                                                      rt.spgraphong.setString(2,ongraph2);
                                                                      rt.spgraphong.setString(3,ongraph3);
                                                                      rt.spgraphong.setString(4,ongraph4);
                                                                      rt.spgraphong.setString(5,ongraph5);
                                                                      rt.spgraphong.setString(6,ongraph6);
     
    rt.spgraphong.execute();
     
    }
    else
     System.out.println("Echec Connexion niveau onglet_graphique"); 
     }
     catch (SQLException f) {
     
    if (f instanceof SQLException){                                                       System.out.println("**onglet_graphique***SQL Error Code is:  " + ((SQLException)f).getErrorCode());                                                          System.out.println("**onglet_graphique****SQL Message Code is: " + f.getMessage());                                                         System.out.println("***onglet_graphique***SQL State is: " + ((SQLException)f).getSQLState());
                                                                }
                                                                System.out.println("***onglet_graphique***Insert failed. " + ((SQLException)f).getMessage());
    return;
     }
     }   
     }
     }
      else{
      while (graphs.hasNext()){
      Graphics grah=(Graphics)graphs.next();
       String g1=grah.getName();
       String g2=canv.getName();
       String g3=frm.getName();
      String g4=frm.getAbsolutePath();
      String g5=GetGraphType(grah.getGraphicsType());
      try{
                                                                       if(rt.connect("BD1","ok","ok")){
     
                                                                           rt.spgraph.setString(1,g1);
                                                                           rt.spgraph.setString(2,g2);
                                                                           rt.spgraph.setString(3,g3);
                                                                           rt.spgraph.setString(4,g4);
                                                                           rt.spgraph.setString(5,g5);  
                                                                           rt.spgraph.execute();
     
                                                                       }
                                                                       else
                                                                           System.out.println("Echec Connexion niveau graphique"); 
     
                                                                   }
                                                                   catch (SQLException f) {
     
                                                                         if (f instanceof SQLException){
                                                                     System.out.println("**graphique***SQL Error Code is:  " + ((SQLException)f).getErrorCode());
                                                                     System.out.println("**graphique****SQL Message Code is: " + f.getMessage());
                                                                     System.out.println("***graphique***SQL State is: " + ((SQLException)f).getSQLState());
                                                                     }
                                                                     System.out.println("***graphique***Insert failed. " + ((SQLException)f).getMessage());
                                                                     return;
                                                                     }
     
     
     
     
     
                               }
                               }      
                       } 
          //Recherche Des Block Niveau Form
                JdapiIterator blockForm = frm.getBlocks();
                while (blockForm.hasNext()){
                    Block blk = (Block)blockForm.next();
                    String blk1=blk.getQualifiedName(false);
                    String blk2=frm.getName();
                    String blk3=frm.getAbsolutePath();
                    String blk4=blk.getDMLDataName();
                    String blk5=blk.getPreviousNavigationBlockName();      
                    String blk6=blk.getNextNavigationBlockName();
                    boolean b7=blk.isDatabaseBlock();
                    boolean b8=blk.isQueryAllowed();
                    boolean b9=blk.isInsertAllowed();
                    boolean b10=blk.isUpdateAllowed();               
                    boolean b11=blk.isDeleteAllowed();
                    String blk12=blk.getWhereClause();
                    String blk13=blk.getOrderByClause();
                    String blk14=blk.getVisualAttributeName();  
                    String blk15="";
                    fw.write("\t*BlocNom:"+blk1+"\n");       
                    fw.write("\t\tModNom:"+blk2+"\n");
                    fw.write("\t\tModChemin:"+blk3+"\n");
                    fw.write("\t\tSource:"+blk4+"\n");
                    fw.write("\t\tBlocNavPrec:"+blk5+"\n");
                    fw.write("\t\tBlocNavSuiv:"+blk6+"\n");
                    fw.write("\t\tBlocBasé:"+b7+"\n");
                    fw.write("\t\tInterrogationAutorisée:"+b8+"\n");
                    fw.write("\t\tInsertionAutorisée:"+b9+"\n");
                    fw.write("\t\tMiseAJourAutorisée:"+b10+"\n");
                    fw.write("\t\tSuppressionAutorisée:"+b11+"\n");
                    fw.write("\t\tWhere Clause:"+blk12+"\n");
                    fw.write("\t\tOderBy Clause:"+blk13+"\n");
                    fw.write("\t\tAttrVis:"+blk14+"\n");
                    fw.write("\t\tBib_Obj_Nom:"+blk15+"\n"); 
                    fw.write("\n");
                   try{     
                        if(rt.connect("BD1","ok","ok")){
                        System.out.println("connexion établie niveau bloc");
                        rt.spbloc.setString(1,blk1);
                        rt.spbloc.setString(2,blk2);
                        rt.spbloc.setString(3,blk3);
                        rt.spbloc.setString(4,blk4);
                        rt.spbloc.setString(5,blk5);
                        rt.spbloc.setString(6,blk6);
                        rt.spbloc.setBoolean(7,b7);
                        rt.spbloc.setBoolean(8,b8);
                        rt.spbloc.setBoolean(9,b9);
                        rt.spbloc.setBoolean(10,b10);
                        rt.spbloc.setBoolean(11,b11);
                        rt.spbloc.setString(12,blk12);
                        rt.spbloc.setString(13,blk13);
                        rt.spbloc.setString(14,blk14);
                        rt.spbloc.setString(15,blk15);
                        rt.spbloc.execute();
                    }
                     else
                     System.out.println("Echec Connexion niveau bloc");
                     }
                       catch (SQLException f) {
                             if (f instanceof SQLException){
                         System.out.println("***bloc****SQL Error Code is:  " + ((SQLException)f).getErrorCode());
                         System.out.println("***bloc****SQL Message Code is: " + f.getMessage());
                         System.out.println("***bloc****SQL State is: " + ((SQLException)f).getSQLState());
                         }
                         System.out.println("***bloc****Insert failed. " + ((SQLException)f).getMessage());
                         return;
                         }
                    //Recherche Des Triggers  Niveau Block 
                    JdapiIterator TrigBlock = blk.getTriggers();
                    while (TrigBlock.hasNext()){
                        Trigger TrigB = (Trigger)TrigBlock.next();
                        String  decb1= TrigB.getName();
                        String  decb2=blk.getQualifiedName(false);
                        String  decb3=frm.getName();
                        String  decb4=frm.getAbsolutePath();
                        String  decb5= TrigB.getTriggerText();
                        String  decb6="";
                        fw.write("\t\t*DecNom:"+decb1+"\n");
                        fw.write("\t\t\tBlocNom:"+decb2+"\n");
                        fw.write("\t\t\tModNom:"+decb3+"\n");
                        fw.write("\t\t\tModChemin:"+decb4+"\n");
                       // fw.write("\t\t\tDecText:"+decb5+"\n");
                        fw.write("\t\t\tItemNom:"+decb6+"\n");
                        fw.write("\n");
                       try{
                          if(rt.connect("BD1","ok","ok")){    
                          System.out.println("connexion établie declencnheur bloc"); 
                             rt.spdecb.setString(1, decb1);
                            rt.spdecb.setString(2,decb2);
                            rt.spdecb.setString(3,decb3);
                             rt.spdecb.setString(4,decb4);
                              rt.spdecb.setString(5,decb5);
                              rt.spdecb.setString(6,decb6);
                              rt.spdecb.execute();
                          }
                          else
                          System.out.println("Echec Connexion declencheur bloc");}
                          catch (SQLException f) {
                                              if (f instanceof SQLException)
                                          {
                                          System.out.println("***declencheur bloc****SQL Error Code is:  " + ((SQLException)f).getErrorCode());
                                          System.out.println("***declencheur bloc****SQL Message Code is: " + f.getMessage());
                                          System.out.println("***declencheur bloc****SQL State is: " + ((SQLException)f).getSQLState());
                                          }
                                          System.out.println("***declencheur bloc****Insert failed. " + ((SQLException)f).getMessage());
                                          return;
                                          }
                    }
                    //Recherche Des Items  Niveau Block 
                    JdapiIterator itemBlock = blk.getItems();
                     while (itemBlock.hasNext()){
                            Item itm = (Item)itemBlock.next();
                            String col1 = itm.getName();
                             String col2=frm.getName();
                            String col3=frm.getAbsolutePath();
                            String col4=blk.getQualifiedName(false);
                            String col5=itm.getCanvasName();
                            String col6=itm.getColumnName();
                            String col7=blk.getDMLDataName();
                             String col8=GetItemType(itm.getItemType());
                             String col9=itm.getLovName();
                             String  col10=itm.getVisualAttributeName();
                              String col11=itm.getLabel();
                                String col12 =itm.getNextNavigationItemName();
                              String col13=itm.getPreviousNavigationItemName();
                              int x14=itm.getXPosition();
                              int x15=itm.getYPosition();
                              int x16=itm.getWidth();
                              int x17=itm.getHeight();
                            fw.write("\t\t*Nom Item:"+col1+"\n");
                             fw.write("\t\t\tModNom:"+col2+"\n");
                             fw.write("\t\t\tModChemin:"+col3+"\n");
                             fw.write("\t\t\tBlocNom:"+col4+"\n");
                             fw.write("\t\t\tCanvasNom:"+col5+"\n");
                             fw.write("\t\t\tColNom:"+col6+"\n");
                             fw.write("\t\t\tSourceNom:"+col7+"\n");
                             fw.write("\t\t\tItemType:"+col8+"\n");
                             fw.write("\t\t\tLovNom:"+col9+"\n");
                             fw.write("\t\t\tAttrVis:"+col10+"\n");
                             fw.write("\t\t\tLabel:"+col11+"\n");
                             fw.write("\t\t\tITEMSuiv:"+col12+"\n");
                             fw.write("\t\t\tITEMPrec:"+col13+"\n");
                             fw.write("\t\t\tPosition X:"+x14+"\n");
                             fw.write("\t\t\tPosition Y:"+x15+"\n");
                             fw.write("\t\t\tLargeur:"+x16+"\n");
                             fw.write("\t\t\tLongueur X:"+x14+"\n");
                        /* try{
                                if(rt.connect("BD1","ok","ok")){    
                                System.out.println("connexion établie niveau item"); 
                                rt.spitem.setString(1, col1);
                                rt.spitem.setString(2, col2);
                                rt.spitem.setString(3, col3);
                                rt.spitem.setString(4, col4);
                                rt.spitem.setString(5, col5);
                                rt.spitem.setString(6, col6);
                                rt.spitem.setString(7, col7);
                                rt.spitem.setString(8, col8);
                                rt.spitem.setString(9, col9);
                                rt.spitem.setString(10, col10);
                                rt.spitem.setString(11, col11);
                                rt.spitem.setString(12, col12);
                                rt.spitem.setString(13, col13);
                                rt.spitem.setInt(14, x14);
                                rt.spitem.setInt(15, x15);
                                rt.spitem.setInt(16, x16);
                                rt.spitem.setInt(17, x17);
                                rt.spitem.execute();
                                System.out.println("insertion de lelement"+col1);      
                                }
                                 else
                                System.out.println("Echec Connexion");}
                                catch (SQLException f) {
                                if (f instanceof SQLException)
                                            {
                                             System.out.println("***niveau item****SQL Error Code is:  " + ((SQLException)f).getErrorCode());
                                             System.out.println("***niveau item****SQL Message Code is: " + f.getMessage());
                                            System.out.println("***niveau item****SQL State is: " + ((SQLException)f).getSQLState());
                                            }
                                            System.out.println("***niveau item****Insert failed. " + ((SQLException)f).getMessage());
                                            return;
                                            }*/
                            //Recherche Des Triggers  Niveau Item
                            JdapiIterator TrigItem = itm.getTriggers();
                            while (TrigItem.hasNext()){
                                Trigger trigitem = ( Trigger)TrigItem.next();
                                    String  decbi1= trigitem.getName();
                                    String decbi2=itm.getName();
                                    String  decbi3=blk.getQualifiedName(false);
                                    String  decbi4=frm.getName();
                                    String  decbi5=frm.getAbsolutePath();
                                    String  decbi6= trigitem.getTriggerText();
                                    String  decbi7="";
                                    fw.write("\t\t*DecNom:"+decbi1+"\n");
                                    fw.write("\t\t\tItemNom:"+decbi2+"\n");
                                    fw.write("\t\t\tBlocNom:"+decbi3+"\n");
                                    fw.write("\t\t\tModNom:"+decbi4+"\n");
                                    fw.write("\t\t\tModChemin:"+decbi5+"\n");
                                   // fw.write("\t\t\tDecText:"+decbi6+"\n");
                                    fw.write("\t\t\tBib_Obj_Nom:"+decbi7+"\n");
                                    fw.write("\n");
      try{
     if(rt.connect("BD1","ok","ok")){
       System.out.println("connexion établie declencheur item");
       rt.spdeci.setString(1, decbi1);
       rt.spdeci.setString(2,decbi2);
       rt.spdeci.setString(3,decbi3);
       rt.spdeci.setString(4,decbi4);
       rt.spdeci.setString(5,decbi5);
       rt.spdeci.setString(6,decbi6);
       rt.spdeci.setString(7,decbi7);
        rt.spdeci.execute();
         }
         else
        System.out.println("Echec Connexion declencheur item");}
        catch (SQLException f) {
          if (f instanceof SQLException)
     
                                        {
                                        System.out.println("****declencheur item*****SQL Error Code is:  " + ((SQLException)f).getErrorCode());
                                        System.out.println("****declencheur item*****SQL Message Code is: " + f.getMessage());
                                        System.out.println("****declencheur item*****SQL State is: " + ((SQLException)f).getSQLState());
                                        }
                                        System.out.println("****declencheur item*****Insert failed. " + ((SQLException)f).getMessage());
                                        return;
                                        }
     
     
                            }
     
                        }
       }
    lorsque j'execute mon programme,aucune erreur ne parait et l'interface apparait mais des que je fait appel a cette methode,le programme se plante.Lorsque j'enleve le code de l'insertion,mon programme marche sans probleme et je peut visualiser les informations sur le fichier.Donc je pense que le probleme vient du fait qu'il ya plusieurs insertions successives.A propos des
    "batch" des preparedStatement,comment les utiliser??
    Merci pour votre attention

  5. #5
    in
    in est déconnecté
    Membre expérimenté Avatar de in
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    1 612
    Détails du profil
    Informations personnelles :
    Localisation : France, Finistère (Bretagne)

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 612
    Points : 1 718
    Points
    1 718
    Par défaut
    Le code c'est bien ... mais ne mets pas tout, juste ce qui est utile. Pour ma part je n'ai rien lu ...

    Juste, pour ta gestion des exceptions, essaie plutot quelques chose comme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
     } catch (SQLException f) {
               if (f instanceof SQLException){ // c'est inutile ...
               //...
               }
     } catch(Exception e) {
        // tu devrais quand même attraper les autres erreurs ...
        System.out.println("Autre exception : "+e.getMessage());
        e.printStackTrace(); // extremement utile pour savoir d'où vient l'erreur
     }
    Pour les "batch", regarde un peu la javadoc, c'est expliqué ...

    En gros le principe :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    PreparedStatement ps = "INSERT ....";
    while(/* parcours de ce que tu veux insérer */ {
        ps.setXXX(1,val1);
        ps.setXXX(2,val2);
        ps.setXXX(3,val3);
     
        ps.addBatch(); // en gros tu prépares un lot de traitement
    }
     
    // hop tout est pret
    ps.executeBatch(); // execute le lot d'instruction
    Par contre, si tu as beaucoup de lignes à insérer, penses à faire un execute/commit de temps en temps, toutes les 1000 lignes par exemple, sinon ça va aggraver les perfs au lieu de les améliorer ...

  6. #6
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Salut,


    Je n'ai pas lu tout le code, mais je ne vois aucun close() donc je dirais que tu ne libère pas tes ressources !

    a++

  7. #7
    Membre du Club
    Inscrit en
    Mai 2008
    Messages
    112
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 112
    Points : 42
    Points
    42
    Par défaut
    j'ai fermé le fichier par un fw.close(); et j'ai fermé aussi la librairie a la fin du code Jdapi.shutdown();
    mais ces deux lignes n'ont pas été envoyé par erreur.y'a t-il autre chose que je dois liberer.le prepareStatement ça se libere ou pas???

  8. #8
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par FstDsi Voir le message
    le prepareStatement ça se libere ou pas???
    Oui : s'il y a une méthode close() ce n'est pas pour rien.
    D'ailleurs ce pas seulement le cas de PreparedStatement mais de toutes les interfaces de JDBC : Connection, Statement, PreparedStatement, Resultet...

    a++

  9. #9
    Membre du Club
    Inscrit en
    Mai 2008
    Messages
    112
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 112
    Points : 42
    Points
    42
    Par défaut
    j'ai essayé de travailler avec le batch et j'ai supprimer ttes les boucles de mon code pour essayer de faire une insertion au moins mais ça ne marche pas.a chaque fois la fenetre d'excution apparait mais se plante des que j'appel la methode d'insertion:
    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
     
    public PreparedStatement ps=null;
     
    private void scan_module_form(String s) {
    FormModule frm = FormModule.open(s);
    JOptionPane c = new JOptionPane();
    String col1=frm.getName();
    String col2=frm.getAbsolutePath();
    String col3=frm.getConsoleWindow();
    String col4=frm.getFirstNavigationBlockName();
    String col5=frm.getMenuModule();
     try{
     DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
     Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:BD1", "ok","ok");
      stmt = conn.createStatement();destinee a  recevoir un ordre SQL
      conn.setAutoCommit(false);
      ps=conn.prepareStatement("insert into form values(?,?,?,?,?)");  
      ps.setString(1,col1);
      ps.setString(2,col2);
      ps.setString(3,col3);
      ps.setString(4,col4);
      ps.setString(5,col5);
      ps.addBatch();
      ps.executeBatch();
      conn.commit();
    ps.close();
            ps=null;
            conn.close();
            conn=null;
     
            rt=null;
            }
     
            catch (SQLException f) {
             if (f instanceof SQLException){
                if( f.getErrorCode()==1)
                JOptionPane.showMessageDialog(c,"Le module est déja scanné","Terminé",JOptionPane.INFORMATION_MESSAGE);
                else{
               System.out.println("*****module******SQL Error Code is:  " + ((SQLException)f).getErrorCode());
               System.out.println("*****module******SQL Message Code is: " + f.getMessage());
               System.out.println("*****module******SQL State is: " + ((SQLException)f).getSQLState());
                }
                }
                System.out.println("*****module******Insert failed. " + ((SQLException)f).getMessage());
                   return;
            }
     
            catch(Exception e) {
                System.out.println("Autre exception : "+e.getMessage());
                e.printStackTrace(); 
             }
     
    }
    Est ce que qq1 aurai une idée de la provenance du probleme???
    Merci

  10. #10
    in
    in est déconnecté
    Membre expérimenté Avatar de in
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    1 612
    Détails du profil
    Informations personnelles :
    Localisation : France, Finistère (Bretagne)

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 612
    Points : 1 718
    Points
    1 718
    Par défaut
    Tu n'as aucun message dans "autre exception" ?

    Comment testes tu ? Tu as une console d'affichée ?

    Qu'est ce que veux dire plante ? La fenêtre se ferme ?

    Tu as suivit le conseil d'adiGuba et tu fermes ton statement, c'est bien ... mais c'est encore mieux de le faire dans un bloc finally. Pour plus d'infos tu peux consulter ceci. Même si c'est avec des flux, le principe est le même ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
     
    private void scan_module_form(String s) {
    		//...
    		try{
    			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    			Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:BD1", "ok","ok");
    			stmt = conn.createStatement();
    			conn.setAutoCommit(false);
     
    			try {
    				ps=conn.prepareStatement("insert into form values(?,?,?,?,?)");  
    				ps.setString(1,col1);
    				ps.setString(2,col2);
    				ps.setString(3,col3);
    				ps.setString(4,col4);
    				ps.setString(5,col5);
    				ps.addBatch();
    				ps.executeBatch();
    				conn.commit();
    			} finally { // ici on ferme dans tous les cas
    				ps.close();
    				conn.close();
    			}
     
     
    		} catch (SQLException f) {
    			if( f.getErrorCode()==1) {
    				JOptionPane.showMessageDialog(c,"Le module est déja scanné","Terminé",JOptionPane.INFORMATION_MESSAGE);
    			}else {
    				System.out.println("*****module******SQL Error Code is:  " + f.getErrorCode());
    				System.out.println("*****module******SQL Message Code is: " + f.getMessage());
    				System.out.println("*****module******SQL State is: " + f.getSQLState());
    			}
    			System.out.println("*****module******Insert failed. " + f.getMessage());
    			f.printStackTrace(); // au moins en phase de dev ...
    		} catch(Exception e) {
    			System.out.println("Autre exception : "+e.getMessage());
    			e.printStackTrace(); 
    		}
     
    	}

Discussions similaires

  1. Insertion dans une base Oracle
    Par saadtv4004 dans le forum Oracle
    Réponses: 6
    Dernier message: 19/05/2011, 16h46
  2. [ODBC] Insertion d'un fichier dans une base oracle 8i via ODBC
    Par garfield_fr dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 09/12/2010, 09h58
  3. Probleme d'insertion dans une base oracle
    Par FstDsi dans le forum JDBC
    Réponses: 7
    Dernier message: 26/05/2008, 12h01
  4. Insertion des fichiers pdf dans une base oracle
    Par arezki76 dans le forum SQL
    Réponses: 2
    Dernier message: 20/07/2007, 16h39
  5. changer le type d'un attribut dans une base oracle 8i
    Par vrossi59 dans le forum Oracle
    Réponses: 3
    Dernier message: 24/02/2006, 15h28

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