日期:2014-05-20  浏览次数:20740 次

JDBC连接oracle,奇怪问题
错误:
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:xe


我的源码:
                  String   strDriver   =   "oracle.jdbc.driver.OracleDriver ";
String   strURL   =   "jdbc:oracle:thin:@localhost:1521:xe ";
String   user   =   "system ";
String   password   =   "yd ";

Connection   conn   =   null;

try   {
Class.forName(strDriver);
conn   =   DriverManager.getConnection(strURL,user,password);
System.out.println( "连接成功! ");
}   catch   (ClassNotFoundException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}


监听文件:
SID_LIST_LISTENER   =
    (SID_LIST   =
        (SID_DESC   =
            (SID_NAME   =   PLSExtProc)
            (ORACLE_HOME   =   C:\oraclexe\app\oracle\product\10.2.0\server)
            (PROGRAM   =   extproc)
        )
        (SID_DESC   =
            (SID_NAME   =   CLRExtProc)
            (ORACLE_HOME   =   C:\oraclexe\app\oracle\product\10.2.0\server)
            (PROGRAM   =   extproc)
        )
    )

LISTENER   =
    (DESCRIPTION_LIST   =
        (DESCRIPTION   =
            (ADDRESS   =   (PROTOCOL   =   IPC)(KEY   =   EXTPROC_FOR_XE))
            (ADDRESS   =   (PROTOCOL   =   TCP)(HOST   =   localhost)(PORT   =   1521))
        )
    )

DEFAULT_SERVICE_LISTENER   =   (XE)


服务中:oracleServerXE                         ----------------那实例号应该是XE吧?

------解决方案--------------------
应该这里错了:1521:xe
你数据库名叫什么,好象不是XE吧?
端口号后面接的是数据库名,也就是实例名