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 :

java.sql.SQLSyntaxErrorException: Tentative de modification d'une colonne d'identité


Sujet :

JDBC Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Par défaut java.sql.SQLSyntaxErrorException: Tentative de modification d'une colonne d'identité
    bonsoir,

    je tente d'inserer un enregistrement dans ma table patient qui est comme ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    create table patient (ref INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1,INCREMENT BY 1), nomp varchar(20), prenomp varchar(20), adresse varchar(50), Cp varchar(5), ville varchar(20), telephone varchar(10), suivi_par varchar(20), type_diabete varchar(1), diagnostic varchar(80));
    j'ai mit INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1,INCREMENT BY 1)pour que cela m'incrémente ref qui était ref varchar(10) primary key auparavant et donc n'incremente pas .

    maintenant quand j'enregistre un enregistrement voici l'erreur que l'on m'affiche:
    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
     
     
    java.sql.SQLSyntaxErrorException: Tentative de modification d'une colonne d'identité 'REF'. 
    	at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    	at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    	at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
    	at ado.ADO.ajouterp(ADO.java:75)
    	at modeles.Fenetre.actionPerformed(Fenetre.java:378)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: org.apache.derby.client.am.SqlException: Tentative de modification d'une colonne d'identité 'REF'. 
    	at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
    	at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
    	at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
    	... 28 more
    si quelqu'un sait pkoi merci!

    nb: j'utilise derby

  2. #2
    Membre Expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Par défaut
    Je suppose vu le message que tu essaies d'insérer une valeur pour cette colonne alors qu'elle est auto-générée (la valeur).

  3. #3
    Membre éclairé Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Par défaut
    oui voila mais j'ai retirer l'insertion du prmier enregistrement comme 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
     
    PreparedStatement psm=connection.prepareStatement("INSERT INTO patient VALUES(?,?,?,?,?,?,?,?,?,?)");
    			//psm.setString(1, refp);
    			psm.setString(2, nomp);
    			psm.setString(3, prenomp);
    			psm.setString(4, adressep);
    			psm.setString(5, cp);
    			psm.setString(6, ville);
    			psm.setString(7, telp);
    			psm.setString(8, suivi_par);
    			psm.setString(9, typed);
    			psm.setString(10, diagnostic);
     
    			int insert = psm.executeUpdate();
    			System.out.println(insert+" ligne insérée");
    			psm.close();

    mais ca me met la meme erreur
    peut etre que je me suit mal prit ?

  4. #4
    Expert éminent

    Avatar de vermine
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    6 582
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2008
    Messages : 6 582
    Par défaut
    Pour que ton test soit complet, il faut également enlever un "?" dans ta requête. Tu insères maintenant 9 valeurs, mais tu lui précises que tu vas en insérer 10.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    PreparedStatement psm=connection.prepareStatement("INSERT INTO patient VALUES(?,?,?,?,?,?,?,?,?)");

  5. #5
    Membre Expert
    Avatar de natha
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 346
    Par défaut
    Et changer les index...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    			int i = 1;
    			//psm.setString(i++, refp);
    			psm.setString(i++, nomp);
    			psm.setString(i++, prenomp);
    			psm.setString(i++, adressep);
    			psm.setString(i++, cp);
    			psm.setString(i++, ville);
    			psm.setString(i++, telp);
    			psm.setString(i++, suivi_par);
    			psm.setString(i++, typed);
    			psm.setString(i++, diagnostic);

  6. #6
    Membre éclairé Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Par défaut
    deja tenté et voici l'erreur générée par ce que tu m'as dit de faire:

    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
     
     
    java.sql.SQLSyntaxErrorException: Le nombre de valeurs attribuées n'est pas le même que le nombre de colonnes spécifiées ou implicites.
    	at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    	at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    	at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
    	at ado.ADO.ajouterp(ADO.java:75)
    	at modeles.Fenetre.actionPerformed(Fenetre.java:379)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: org.apache.derby.client.am.SqlException: Le nombre de valeurs attribuées n'est pas le même que le nombre de colonnes spécifiées ou implicites.
    	at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
    	at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
    	at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
    	at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
    	at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
    	... 28 more
    vu que la colonne ref est auto-incrementer cela devait marcher mais non.
    bizarre ?
    si quelqu'un a deja rencontrée ce probleme merci.

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 20/12/2011, 09h37
  2. Réponses: 1
    Dernier message: 30/08/2011, 09h53
  3. [Oracle 9i] aide modification d'une colonne
    Par bubblelicious dans le forum Langage SQL
    Réponses: 7
    Dernier message: 02/03/2006, 15h29
  4. [Access] Modification d'une colonne ...
    Par hobotalker dans le forum Langage SQL
    Réponses: 2
    Dernier message: 27/02/2006, 11h03
  5. [DB2]Modification d'une colonne
    Par ahoyeau dans le forum DB2
    Réponses: 4
    Dernier message: 08/10/2004, 00h24

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