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 :

[JDBC] java.sql.SQLException: Closed Statement


Sujet :

JDBC Java

  1. #1
    Membre à l'essai
    Inscrit en
    Juillet 2003
    Messages
    25
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 25
    Points : 18
    Points
    18
    Par défaut [JDBC] java.sql.SQLException: Closed Statement
    Bonjour,
    Je créé un prepared statement qui doit supprimer des lignes, je le complète et, au momment ou je fais mon executeUpdate(), il me sort
    une java.sql.SQLException: Closed Statement ... alors que bien entendu, je ne ferme pas mon statement avant!!! (A moins que vous insistiez je ne met pas mon code car il est assez longet compliqué).
    J'ai l'habitude des prepared Statement mais surtout avec des requetes de type INSERT, alors que là, c'est un DELETE.
    Mis à part celà, mon accés à la base est tout à fait correct, et cette erreur tombe systématiquement sur le executeUpdate().
    Quelqu'un aurait il une idée de ce qu'il peut se passer?
    Merci
    cm

  2. #2
    Membre habitué Avatar de XristofGreek
    Inscrit en
    Août 2004
    Messages
    164
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 164
    Points : 174
    Points
    174
    Par défaut
    malheureusement je crois qu'il va nous falloir un peu plus d'infos...du code par exemple...
    les gens qui s'ennuient sont des gens sans imagination.

  3. #3
    Membre à l'essai
    Inscrit en
    Juillet 2003
    Messages
    25
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 25
    Points : 18
    Points
    18
    Par défaut
    Voilà voilà :

    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
     
     
     /** Method to delete a line of data of a specified table
       * @param table_name the name of the table
       * @param columns_of_primary_key_constraint the list of the columns of the primary key constraint of the table
       */ 
           public void launchQueryDeleteALineFromATable(String table_name, ArrayList columns_of_primary_key_constraint_ArrayList, ArrayList  values_of_primary_key_constraint_ArrayList ){
     
             int i;
             i=0;
             String type_of_column;
     
             String ps;
     
             ps = "DELETE FROM " + table_name + " WHERE " + columns_of_primary_key_constraint_ArrayList.get(i) + " = ?";
             for (i=1; i< columns_of_primary_key_constraint_ArrayList.size(); i++){
                ps = ps + " AND "+ columns_of_primary_key_constraint_ArrayList.get(i) + " = ?";
             }
             System.out.println("ps" + ps);           	
     
             try{
                this.create_prepared_Statement(ps); 
                i=0;
                for(i=0; i<columns_of_primary_key_constraint_ArrayList.size() ;i++){
                   type_of_column = getTypeOfAColumn(table_name,(String)columns_of_primary_key_constraint_ArrayList.get(i));
                   System.out.println("coucou");
     
                   if(type_of_column.equals("REAL")){
                      double double_temp_value_for_insertion = new Double((String)values_of_primary_key_constraint_ArrayList.get(i)).doubleValue();
                      this.complete_preparedStatement(i+1, double_temp_value_for_insertion );              
                   }
                   else{
                      if(type_of_column.equals("INTEGER")){
                         int int_temp_value_for_insertion = new Integer((String)values_of_primary_key_constraint_ArrayList.get(i)).intValue();
                         this.complete_preparedStatement(i+1, int_temp_value_for_insertion );        
                      }
                      else{
                         if(type_of_column.equals("DATE")){
                            java.sql.Timestamp timestamp_temp_value_for_insertion;
                            try{
                               timestamp_temp_value_for_insertion = java.sql.Timestamp.valueOf((String)values_of_primary_key_constraint_ArrayList.get(i));
                            }
                                catch (java.lang.IllegalArgumentException e) { 
                                  timestamp_temp_value_for_insertion = null;
                               } 
                            this.complete_preparedStatement(i+1, timestamp_temp_value_for_insertion );   
                         }
                         else{
                            if(type_of_column.equals("STRING")){
                               System.out.println("STRING");
                               System.out.println("i+1" + (i+1));
                               System.out.println("values_of_primary_key_constraint_ArrayList.get(i)" + values_of_primary_key_constraint_ArrayList.get(i));
                               this.complete_preparedStatement(i+1, (String)values_of_primary_key_constraint_ArrayList.get(i) );  
                            }
                            else{
                               if(type_of_column.equals("BOOLEAN")){
                                  boolean boolean_temp_value_for_insertion = new Boolean((String)values_of_primary_key_constraint_ArrayList.get(i)).booleanValue();
                                  this.complete_preparedStatement(i+1, boolean_temp_value_for_insertion );       
                               }
                               else{
                                  System.out.println("type_of_column"+ type_of_column );
                                  this.complete_preparedStatement(i+1, (String)values_of_primary_key_constraint_ArrayList.get(i) ); 
                               }
                            }
                         }
                      }
                   }
     
     
                }
                System.out.println("coucou2");
                this.execUpdate();  
                System.out.println("coucou4");    
                this.end_of_preparedStatement();  
                System.out.println("coucou5");
             }
                 catch (SQLException sqlex){
                   System.err.println("SQLException : launchQueryDeleteALineFromATable");
                   sqlex.printStackTrace();
                }
          }
     
     
     
     
     
     
    //Pour diverses raisons j'ai reprogrammé les méthodes jdbc, les voici
     
     
     
     
     
     
     
     
     
     
     
     
     
      /** Execute an "insert" or "update" query 
       * @throws SQLException Mainly in case of database inaccessible or incorrect query 
       */
           private static void execUpdate()
           throws SQLException
          {
             pstmt.executeUpdate();
          }
     
     
     
      /** Launch a prepared Statement (pattern of query) to the database 
       * @param preparedStatementQuery String representing the query
       * @throws SQLException Mainly in case of database inaccessible or querry badly writen
       */
           private static void create_prepared_Statement( String preparedStatementQuery )
           throws SQLException
          {              
          // Create a prepared Statement
             pstmt = conn.prepareStatement (preparedStatementQuery);
     
          }
     
       /** Complete a prepared Statement (pattern of query) with a value 
       * @param position Is the position of the value in the querie (1 = First missing value, 2 second....)
       * @param val Is the value we put to complete the prepared Statement. Here it's a String
       * @throws SQLException Mainly in case of database inaccessible or bad position (if there is two missing values in the prepared statement and we recieve 3 as position) 
       */
           private static void complete_preparedStatement(int position, String val)
           throws SQLException
          {
             pstmt.setString(position, val);
     
     
          }
     
       /** Complete a prepared Statement (pattern of query) with a value 
       * @param position Is the position of the value in the querie (1 = First missing value, 2 second....)
       * @param val Is the value we put to complete the prepared Statement. Here it's a  int
       * @throws SQLException Mainly in case of database inaccessible or bad position (if there is two missing values in the prepared statement and we recieve 3 as position) 
       */
           private static void complete_preparedStatement(int position, int val)
           throws SQLException
          {
             pstmt.setInt(position, val);       
          }
    //.... pour tout les types

    A l'exécutions ça me donne ça :

    psDELETE FROM LOCATION WHERE ID_LOCATION = ?
    coucou
    STRING
    i+11
    values_of_primary_key_constraint_ArrayList.get(i)new14
    coucou2
    SQLException : launchQueryDeleteALineFromATable
    java.sql.SQLException: Closed Statement
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java)
    at Database.execUpdate(Database.java:1396)
    at Database.launchQueryDeleteALineFromATable(Database.java:6193)
    at TableWindow.actionPerformed(TableWindow.java:271)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
    at java.awt.Component.processMouseEvent(Component.java:5134)
    at java.awt.Component.processEvent(Component.java:4931)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3639)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Window.dispatchEventImpl(Window.java:1590)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    En espérant que ça ne vous perde pas et que quelqu'un puisse m'aider,
    cm

  4. #4
    Membre habitué
    Inscrit en
    Juillet 2004
    Messages
    152
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 152
    Points : 173
    Points
    173
    Par défaut
    Le fait que ton PreparedStatement soit static ne me semble pas etre une bonne chose.

  5. #5
    Membre à l'essai
    Inscrit en
    Juillet 2003
    Messages
    25
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 25
    Points : 18
    Points
    18
    Par défaut
    J'ai trouvé, merci pour ta remarque, en effet, getTypeOfAColumn que j'appelle juste après avoir créé mon prepared Statement ps crée elle aussi un prepared Statement et comme je n'en ai qu'un possible dans ma classe car static..... ps passe à la trappe.
    Merci beaucoup,
    Il va falloir que je repense cette histoire de Prepared Statement car effectivement, ce n'est pas terrible.
    Merci encore,
    cm

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 19/02/2009, 11h59
  2. Réponses: 1
    Dernier message: 04/06/2008, 23h22
  3. [JDBC] Erreur java.sql.SQLException: Io exception: Broken pipe pool tomcat
    Par lbd_9C dans le forum Interfaces de programmation
    Réponses: 0
    Dernier message: 29/05/2008, 18h00
  4. Réponses: 7
    Dernier message: 11/08/2006, 09h24
  5. Réponses: 3
    Dernier message: 24/11/2005, 12h24

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