Java

Oracle XE 11g (ORA-12514: TNS:listener 目前不知道連接描述符中請求的服務)

  • March 15, 2015

我已經在堆棧溢出中看到了可能與我的問題有關的問題,但讓我強調一下,它們都不能解決我的問題。

問題是:當我想將 OWASP WebGoat 應用程序與 oracle XE 11g 集成時,我收到上述錯誤。

web.xml 中的連接 URL 為:

jdbc:oracle:thin:@//localhost:1521/XE/${USER}

=================================================== =============== listener.ora:

SID_LIST_LISTENER =
 (SID_LIST =
   (SID_DESC =
     (SID_NAME = PLSExtProc)
     (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
     (PROGRAM = extproc)
   )
   (SID_DESC =
     (SID_NAME = CLRExtProc)
     (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
     (PROGRAM = extproc)
   )
 )

LISTENER = 
 (DESCRIPTION_LIST =
   (DESCRIPTION =
     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
     (ADDRESS = (PROTOCOL = TCP)(HOST = Amir-PC)(PORT = 1521))
   )
 )

DEFAULT_SERVICE_LISTENER = (XE)

=================================================== ========== tnsnames.ora:

XE =
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = Amir-PC)(PORT = 1521))
   (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME = XE)
   )
 )



EXTPROC_CONNECTION_DATA =
 (DESCRIPTION =
   (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
   )
   (CONNECT_DATA =
     (SID = PLSExtProc)
     (PRESENTATION = RO)
   )
 )

ORACLR_CONNECTION_DATA = 
 (DESCRIPTION = 
   (ADDRESS_LIST = 
     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) 
   ) 
   (CONNECT_DATA = 
     (SID = CLRExtProc) 
     (PRESENTATION = RO) 
   ) 
 ) 

==================================================== ================= java版本:

java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) Client VM (build 24.55-b03, mixed mode, sharing)

==================================================== ================= lsnrctl 服務的輸出:

LSNRCTL for 32-bit Windows: Version 11.2.0.2.0 - Production on 09-MAY-2014 16:34
:07

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
 Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
   Handler(s):
     "DEDICATED" established:0 refused:0
        LOCAL SERVER
Service "PLSExtProc" has 1 instance(s).
 Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
   Handler(s):
     "DEDICATED" established:0 refused:0
        LOCAL SERVER
Service "XEXDB" has 1 instance(s).
 Instance "xe", status READY, has 1 handler(s) for this service...
   Handler(s):
     "D000" established:0 refused:0 current:0 max:1022 state:ready
        DISPATCHER <machine: AMIR-PC, pid: 5740>
        (ADDRESS=(PROTOCOL=tcp)(HOST=Amir-PC)(PORT=2403))
Service "xe" has 1 instance(s).
 Instance "xe", status READY, has 1 handler(s) for this service...
   Handler(s):
     "DEDICATED" established:0 refused:0 state:ready
        LOCAL SERVER
The command completed successfully

==================================================== =================== tnsping xe 的輸出:

TNS Ping Utility for 32-bit Windows: Version 11.2.0.2.0 - Production on 09-MAY-2
014 16:35:19

Copyright (c) 1997, 2010, Oracle.  All rights reserved.

Used parameter files:
C:\oraclexe\app\oracle\product\11.2.0\server\network\admin\sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Amir-PC)
(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))
OK (0 msec)

有人可以幫我解決這個問題嗎?我已經苦苦掙扎了 3 天多,還沒有找到任何有用的答案。

在評論中你說你的web.xml包含:

<init-param>
<param-name>DatabaseConnectionString</param-name>
<!-- The string "${USER}" in the connection string will be replaced
     by the active username when making a connection. -->
<param-value>
 <!--jdbc:hsqldb:mem:${USER}-->
 <!--jdbc:oracle:thin:@127.0.0.1:1521:xe/${USER}-->
 jdbc:oracle:thin:@localhost:1521
</param-value>
</init-param>

您在問題頂部顯示的連接字元串已被註釋掉,因此您實際上是使用jdbc:oracle:thin:@localhost:1521. 那不是提供服務名稱;但你listener.ora確實有DEFAULT_SERVICE_LISTENER = (XE)所以這應該相當於 jdbc:oracle:thin:@localhost:1521/XE. (我已經用 11gR2 EE 對此進行了測試,並且 in 周圍的括號XE似乎listener.ora無關緊要)。

但這似乎並不像預期的那樣工作。當您更改並明確設置使用者名時:

jdbc:oracle:thin:system/system@//localhost:1521/XE

… TNS-12514 消失了,取而代之的是 ORA-01017,無效的使用者名/密碼。這意味著連接字元串現在正在工作,並且您的system帳戶密碼不是system. 使用有效的使用者名和密碼,它現在看起來應該可以工作了。

如果${USER}替換按照web.xml建議中的註釋工作,並且包含使用者名和密碼,那麼使您的連接字元串看起來像這樣應該可以工作:

jdbc:oracle:thin:${USER}@//localhost:1521/XE

但只有 if${USER}實際上是一個有效的username/password字元串。

引用自:https://dba.stackexchange.com/questions/64848