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 :

[HSQLDB]Problèmes avec requête


Sujet :

JDBC Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut [HSQLDB]Problèmes avec requête
    Bonjour

    Dans mon programme, lors du premier lancement, je lance la connexion sur une base de données hsql, jusque là, pas de problèmes, tout marche bien. Mais ensuite, j'initialise cette base de données avec cette méthode :

    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
    protected void initializeDb(){
    		Statement statement = null;
    		try {
    			statement = connection.createStatement();
     
    			//Création de la table film
    			statement.executeUpdate("CREATE TABLE film " +
    		        "(ID INT(11) NOT NULL AUTO_INCREMENT, nom VARCHAR(100) NOT NULL, genre INT(11) NOT NULL, type INT(11) NOT NULL" +
    		        ", annee INT(11) NOT NULL, duree INT(11) NOT NULL, state INT(11) NOT NULL, realisateur INT(11) NOT NULL, " +
    		        "langue INT(11) NOT NULL, location INT(11) NOT NULL, note INT(11) NOT NULL,INDEX (ID))");
     
    			...
     
    		} catch (SQLException e) {
    			e.printStackTrace();
    		} finally{
    			try { statement.close();} catch (SQLException e) {e.printStackTrace();}
    		}
    	}
    et là, il me fait une l'erreur suivante :

    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
    java.sql.SQLException: Unexpected token in statement [CREATE TABLE film (ID INT(11]
    	at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    	at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
    	at org.hsqldb.jdbc.jdbcStatement.executeUpdate(Unknown Source)
    	at jTheque.Fonctions.initializeDb(Fonctions.java:177)
    	at jTheque.GuiFirstStart$1.mouseClicked(GuiFirstStart.java:128)
    	at java.awt.AWTEventMulticaster.mouseClicked(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.pumpOneEventForHierarchy(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)
    Elle pointe sur la ligne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    statement.executeUpdate("CREATE TABLE film " +
    		        "(ID INT(11) NOT NULL AUTO_INCREMENT, nom VARCHAR(100) NOT NULL, genre INT(11) NOT NULL, type INT(11) NOT NULL" +
    		        ", annee INT(11) NOT NULL, duree INT(11) NOT NULL, state INT(11) NOT NULL, realisateur INT(11) NOT NULL, " +
    		        "langue INT(11) NOT NULL, location INT(11) NOT NULL, note INT(11) NOT NULL,INDEX (ID))");
    Est-ce que vous savez d'ou ca viens ? Y a t'il des limitations avec HSQL ?

    P.S. J'ai testé cette méthode sur une base de données mysql et elle marche tout à fait bien.

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    109
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 109
    Par défaut
    As tu essayé de l'exécuter dans le requeteur de hsql ?
    Je ne crois pas que auto_increment existe sous hsql

  3. #3
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    Citation Envoyé par MangeurVasqué
    As tu essayé de l'exécuter dans le requeteur de hsql ?
    Je ne crois pas que auto_increment existe sous hsql
    Aie, ca me ferait mal, toute mon appli fonctionne avec l'auto incrément

    Quelqu'un a d'autres infos ?

    Je vais aller revoir sur internet, voir si quelque chose ne m'a pas échappé...

  4. #4
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    Ouf, je suis sauvé. En fait c'est la syntaxe qui est différente, en effet, pour faire de l'auto incrément sur une base hsql, il faut employer GENERATED BY DEFAULT AS IDENTITY et pas AUTO INCREMENT.

    Citation Envoyé par www.hsqldb.org
    Identity Auto-Increment Columns
    Each table can contain one auto-increment column, known as the IDENTITY column. An IDENTITY column is always treated as the primary key for the table (as a result, multi-column primary keys are not possible with an IDENTITY column present). Support has been added for CREATE TABLE <tablename>(<colname> IDENTITY, ...) as a shortcut.

    Since 1.7.2, the SQL standard syntax is used by default, which allows the initial value to be specified. The supported form is(<colname> INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH n, [INCREMENT BY m])PRIMARY KEY, ...). Support has also been added for BIGINT identity columns. As a result, an IDENTITY column is simply an INTEGER or BIGINT column with its default value generated by a sequence generator.

    When you add a new row to such a table using an INSERT INTO <tablename> ...; statement, you can use the NULL value for the IDENTITY column, which results in an auto-generated value for the column. The IDENTITY() function returns the last value inserted into any IDENTITY column by this connection. Use CALL IDENTITY(); as an SQL statement to retrieve this value. If you want to use the value for a field in a child table, you can use INSERT INTO <childtable> VALUES (...,IDENTITY(),...);. Both types of call to IDENTITY() must be made before any additional update or insert statements are issued on the database.

  5. #5
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    En fait l'erreur ne venait pas que de là malheureusement, mais il me semble qu'elle est générale chez moi...

    J'ai simplifié ma requête maintenant et j'ai essayé avec ca :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    String query = "CREATE TABLE FILM (id INT(11))";
     
    //Création de la table film
    statement.executeUpdate(query);
    et j'ai toujours une l'exception que voici qui est levée :

    java.sql.SQLException: Unexpected token in statement [CREATE TABLE FILM (id INT(11]
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.jdbcStatement.executeUpdate(Unknown Source)
    at jTheque.Fonctions.initializeDb(Fonctions.java:196)
    at jTheque.GuiFirstStart$1.mouseClicked(GuiFirstStart.java:128)
    at java.awt.AWTEventMulticaster.mouseClicked(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.pumpOneEventForHierarchy(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)
    Je vois pas ce qu'il peut y avoir de faux dans ce bout de code...

    Alors soit je suis nul, soit mon driver hsql est fou, soit c'est la fin du monde, soit je ne sais pas ce qu'il se passe...

  6. #6
    Expert confirmé
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Par défaut
    Je viens en fait de réaliser une chose importante avec du HSQL, comme c'est une base en java, on peut pas dire la valeur maximale d'un int, un int c'est une int et rien d'autres...

    Donc on peut pas avoir des syntaxes tels que INT(11), il faut mettre INT ou INTEGER à place.

  7. #7
    Membre émérite
    Avatar de bbclone
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    537
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2006
    Messages : 537
    Par défaut
    essaye d'enlever la precision int(11) et laisse juste int?

    je croi que tu peut dire numeric(11) mais pas int(11) sur HSQLDB
    int(11) c'est mySQL :-)

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

Discussions similaires

  1. Problèmes avec Requêtes d'extraction 2
    Par NoBru dans le forum Access
    Réponses: 4
    Dernier message: 06/06/2006, 22h05
  2. Problèmes avec Requêtes d'extraction
    Par NoBru dans le forum Access
    Réponses: 3
    Dernier message: 03/06/2006, 15h25
  3. Problème avec requête ajout
    Par teffal dans le forum Access
    Réponses: 3
    Dernier message: 29/04/2006, 16h41
  4. Problème avec requête ajout
    Par mitnick32 dans le forum Access
    Réponses: 1
    Dernier message: 02/02/2006, 18h02
  5. [VB6] Problème avec requête Update
    Par bb62 dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 02/02/2006, 03h40

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