Connexion de java avec une base de données oracle

Aminesrine88 Messages postés 2 Date d'inscription vendredi 17 septembre 2010 Statut Membre Dernière intervention 5 juillet 2011 - 5 juil. 2011 à 14:26
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 - 8 juil. 2011 à 11:16
Bonjour,
j'utilise JAVA et j'essaie d'établir une connexion avec une base de données oracle.
J'ai écrit ce code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package test2;


import java.sql.*;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
       Class.forName ("oracle.jdbc.OracleDriver");

        Connection conn = DriverManager.getConnection
            ("jdbc:oracle:thin:@localhost:1521:cei", "****", "****");
                            // @//machineName:port/SID,   userid,  password
       try {
        Statement stmt = conn.createStatement();
        try {
        ResultSet rset = stmt.executeQuery("select * from fonction");
        try {
        while (rset.next())
              System.out.println (rset.getString(1));   // Print col 1
        } finally {
            try { rset.close(); } catch (Exception ignore) {}
        }
        } finally {
            try { stmt.close(); } catch (Exception ignore) {}
        }
        } finally {
            try { conn.close(); } catch (Exception ignore) {}
        }
  }
}

L'erreur suivante s'affiche:
Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:cei
Merci

3 réponses

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
5 juil. 2011 à 14:48
Le sid que tu as entré n'est pas le bon, consulte le fichier init.ora dans le dossier d'installation d'oracle
0
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
5 juil. 2011 à 14:52
Si ca ne marche toujours pas, tu peux jeter un œil ici : http://www.javafr.com/codes/CONNEXION-BASE-ORACLE_53290.aspx
0
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
8 juil. 2011 à 11:16
Est ce que ma réponse te convient ? Si elle ne te convient pas, qu'est ce qui pose problème ? Toujours pareil ?
0
Rejoignez-nous