Aminesrine88
Messages postés2Date d'inscriptionvendredi 17 septembre 2010StatutMembreDernière intervention 5 juillet 2011
-
5 juil. 2011 à 14:26
cs_Julien39
Messages postés6414Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention29 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