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 :

Connexion à une base MySQL


Sujet :

JDBC Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    440
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 440
    Points : 184
    Points
    184
    Par défaut Connexion à une base MySQL
    Bonjour

    J'ai essayé la procédure qui se trouve http://www.oracle.com/technology/pro...and_oc4j3.html et ca ne foncionne absolument pas. Je me retrouve avec une multitude d'erreurs. Mais j'ai besoin d'utiliser MySQL parce que je veux offrir à mes clients un support de Oracle et MySQL. Alors j'aimerais savoir si vous savez comment faire fonctionner JDeveloper 10.1.3 avec MySQL?

    Merci

  2. #2
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Euh, dis nous plutôt les erreurs que tu obtiens, ça nous aidera plus.

    Ensuite JDevelopper n'est qu'un IDE, et les projets qu'il permet de faire sont cécris en java, or java supporte un grand nombre de bases de données.

    Donc ta question concerne plutôt java que jdev
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    440
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 440
    Points : 184
    Points
    184
    Par défaut
    Ah bon désolé lol

    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
    import java.sql.*;
     
     
    public void someMethod()
    {
      Connection jdbcConnection = null;
     
      try
      {
        Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
        jdbcConnection = DriverManager.getConnection(
          "jdbc:mysql://mylinuxbox.uk.oracle.com/testdatabase?user=testuser&password=mypassword"
        );
        jdbcConnection.connect();
     
        Statement stmt = jdbcConnection.createStatement();
        ResultSet results = statement.executeQuery(
          "SELECT id, name FROM employees"
        );
     
        while ( results.next() )
        {
          System.out.println( "Employee name is "+results.getString( 2 ) );
        }
        results.close();
     
      }
      catch ( Exception e )
      {
        // .. TODO: handle exception gracefully
      }	
      finally
      {
        try
        {
          jdbcConnection.close();
        }
        catch ( SQLException sqle )
        {
          // ..
        }
      }
     
    }
    1-Tout d'abord: jdbcConnection.connect(); (il me dit method connect() not found)
    2-statement.executeQuery (il me dit Type or variable statement not found)

    Voilà pour le moment c'est tous ce que j'ai mais c'est assez majeur

    Merci à l'avance!

  4. #4
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Commence par retirer le jdbcConnection.connect(), pour mysql il ne sert à rien (d'ailleurs je ne suis pas sur qu'il soit franchement utile pour oracle non plus. D'ailleurs cette méthode n'existe pas dans l'interface Connection.

    Et si tu veux pouvoir tester mysql sans te poser de problème je te suggére de t'intaller une base mysql en local. Ce sera un peu plus serein que de tapper dans la base mise ne place par oracle.
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    440
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 440
    Points : 184
    Points
    184
    Par défaut
    Donc ma méthode devrait ressemblé à ceci:

    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
      Connection jdbcConnection = null;
     
      try
      {
        Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
        jdbcConnection = DriverManager.getConnection(
          "jdbc:mysql://localhost/kwn?user=root&password=******"
        );
     
        Statement stmt = jdbcConnection.createStatement();
        ResultSet results = stmt.executeQuery(
          "SELECT id, name FROM employees"
        );
     
        while ( results.next() )
        {
          System.out.println( "Employee name is "+results.getString( 2 ) );
        }
        results.close();
     
      }
      catch ( Exception e )
      {
        e.printStackTrace();
      }	
      finally
      {
        try
        {
          jdbcConnection.close();
        }
        catch ( SQLException sqle )
        {
          sqle.printStackTrace();
        }
      }
    Est-ce bien ca?

  6. #6
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Pas pour la chaîne de connexion, ce serait plutôt de cette forme:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DriverManager.getConnection("jdbc:mysql://localhost/maBase","user","pwd");
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  7. #7
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    440
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 440
    Points : 184
    Points
    184
    Par défaut
    Le KWN est en fait mon schema par défaut mais comment je fais pour savoir le nom de la base (je suis complètement nouveau à MySQL )

  8. #8
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    le nom de ta base est celui de ton schéma

    dans ton cas ça donnera

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     "jdb:mysql://localhost/kvn"
    comme url de connexion
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  9. #9
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    440
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 440
    Points : 184
    Points
    184
    Par défaut
    Super ca fonctionne!!! Merci infiniment!

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

Discussions similaires

  1. Pertinence d'une connexion à une base mysql.
    Par gigigao dans le forum Visual C++
    Réponses: 4
    Dernier message: 11/08/2006, 11h43
  2. connexion à une base mysql
    Par mealtone dans le forum SQL Procédural
    Réponses: 2
    Dernier message: 30/06/2006, 23h23
  3. connexion à une base mysql wxdevcpp
    Par altadeos dans le forum Autres éditeurs
    Réponses: 1
    Dernier message: 06/04/2006, 09h34
  4. [BDD] Erreur dans la connexion à une base MySQL
    Par dodo10 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 24/01/2005, 19h52
  5. [JSP] Connexion à une base mysql
    Par Jovial dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 20/04/2004, 14h04

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