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

  1. #1
    Membre averti 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
    Points : 355
    Points
    355
    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
    Points : 3 083
    Points
    3 083
    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).
    Comment ça ? La réponse à ton problème n'est ni dans la faq, ni dans les tutos, ni dans sources ??? Etonnant...
    De la bonne manière de poser une question (et de répondre).
    Je ne fais pas de service par MP. Merci (...de lire les règles...).
    Ma page dvp.com

  3. #3
    Membre averti 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
    Points : 355
    Points
    355
    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 sénior

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

    Informations forums :
    Inscription : Mars 2008
    Messages : 6 582
    Points : 79 912
    Points
    79 912
    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
    Points : 3 083
    Points
    3 083
    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);
    Comment ça ? La réponse à ton problème n'est ni dans la faq, ni dans les tutos, ni dans sources ??? Etonnant...
    De la bonne manière de poser une question (et de répondre).
    Je ne fais pas de service par MP. Merci (...de lire les règles...).
    Ma page dvp.com

  6. #6
    Membre averti 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
    Points : 355
    Points
    355
    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.

  7. #7
    Expert éminent sénior

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

    Informations forums :
    Inscription : Mars 2008
    Messages : 6 582
    Points : 79 912
    Points
    79 912
    Par défaut
    J'ai déjà eu ce message d'erreur. J'ai retapé toute ma requête en la fractionnant en petite partie. D'abord insérer un champs, puis deux, puis trois, ... Et pour finir cela fonctionnait alors que ma requête finale était exactement la même que la première.

  8. #8
    Membre averti 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
    Points : 355
    Points
    355
    Par défaut
    salut,

    non, ca ne marche toujours car meme en essayant de rajouter juste le premier champs sans les autres il me mettent la meme erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    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.
    voici ma la definition de ma table:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    create table patient (ref INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1,INCREMENT BY 1), nomp varchar(20) not null, 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), UNIQUE (ref, nomp));

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

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 311
    Points : 9 525
    Points
    9 525
    Billets dans le blog
    1
    Par défaut
    C'est normal que ça ne fonctionne pas, tu fais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    insert into patient values(...)
    ce qui implique que tu passes autant de paramètres qu'il y a de colonnes dans la table...
    Hors toi, tu ne passes pas la valeur de la colonne ref, donc, il faudrait faire ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    insert into patient(col2, col3, ..., coln) values(val2, val3, ..., valn)
    A+
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

+ 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