2014-04-11 39 views
3

我正在刪除需要訪問Oracle數據庫的Java應用程序。到目前爲止,我已經使用ojdbc6驅動程序沒有任何問題。現在我們將數據庫切換到Oracle 12c,所以我想使用更新的JDBC驅動程序。使用TNS別名與ojdbc 12.1

這是代碼

public class jdbctest { 
    public static void main(String[] args) throws Exception { 
    final PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); 
    oracle.jdbc.OracleDriver.main(args); 
    System.setProperty("oracle.net.tns_admin", "c:/Windows/System32/oracle-home/network/admin"); 
    pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); 
    pds.setURL("jdbc:oracle:thin:@TNSALIASWITHOUTDOTS"); 
    System.out.println("Opening connection..."); 
    final Connection connection = pds.getConnection(); 
    System.out.println("Connection opened"); 
    } 
} 

這是在tnsnames.ora(HOST改變,因爲這是在我們的內聯網的東西)

TNSALIAS.WITH.DOTS = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = testdomain.de) (PORT = 1521)))(CONNECT_DATA = (SID = EDISW))) 
TNSALIASWITHOUTDOTS = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = testdomain.de) (PORT = 1521)))(CONNECT_DATA = (SID = EDISW))) 

這是輸出所有四個變化(2驅動器,2個tnsaliases) JDBC 11.2,TNSALIASWITHOUTDOTS

Oracle 11.2.0.3.0 JDBC 4.0 compiled with JDK6 on Fri_Aug_26_08:19:15_PDT_2011 
#Default Connection Properties Resource 
#Mon Apr 14 09:25:15 CEST 2014 
Opening connection... 
Exception in thread "main" java.sql.SQLException: Exception beim Abrufen der Connection: oracle.ucp.UniversalConnectionPoolException: Connection kann nicht aus Datenquelle abgerufen werden: java.sql.SQLException: ORA-01017: Benutzername/Kennwort ungültig; Anmeldung abgelehnt 
    at oracle.ucp.util.UCPErrorHandler.newSQLException(UCPErrorHandler.java:488) 
    at oracle.ucp.util.UCPErrorHandler.throwSQLException(UCPErrorHandler.java:163) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1055) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:985) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:966) 
    at jdbctest.main(jdbctest.java:18) 
Caused by: oracle.ucp.UniversalConnectionPoolException: Connection kann nicht aus Datenquelle abgerufen werden: java.sql.SQLException: ORA-01017: Benutzername/Kennwort ungültig; Anmeldung abgelehnt 
    at oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:368) 
    at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:49) 
    at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:80) 
    at oracle.ucp.jdbc.DataSourceConnectionFactoryAdapter.createConnection(DataSourceConnectionFactoryAdapter.java:102) 
    at oracle.ucp.jdbc.oracle.OracleDataSourceConnectionFactoryAdapter.createConnection(OracleDataSourceConnectionFactoryAdapter.java:82) 
    at oracle.ucp.common.UniversalConnectionPoolImpl$UniversalConnectionPoolInternal.createOnePooledConnectionInternal(UniversalConnectionPoolImpl.java:1776) 
    at oracle.ucp.common.UniversalConnectionPoolImpl$UniversalConnectionPoolInternal.access$600(UniversalConnectionPoolImpl.java:1612) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.createOnePooledConnection(UniversalConnectionPoolImpl.java:588) 
    at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.createOnePooledConnection(OracleJDBCConnectionPool.java:170) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionWithoutCountingRequests(UniversalConnectionPoolImpl.java:354) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionAndValidate(UniversalConnectionPoolImpl.java:167) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnection(UniversalConnectionPoolImpl.java:148) 
    at oracle.ucp.jdbc.JDBCConnectionPool.borrowConnection(JDBCConnectionPool.java:166) 
    at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.borrowConnection(OracleJDBCConnectionPool.java:1441) 
    at oracle.ucp.jdbc.oracle.OracleConnectionConnectionPool.borrowConnection(OracleConnectionConnectionPool.java:82) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1043) 
    ... 3 more 

JDBC 11。 2個TNSALIAS.WITH.DOTS

Oracle 11.2.0.3.0 JDBC 4.0 compiled with JDK6 on Fri_Aug_26_08:19:15_PDT_2011 
#Default Connection Properties Resource 
#Mon Apr 14 09:27:50 CEST 2014 
Opening connection... 
Exception in thread "main" java.sql.SQLException: Exception beim Abrufen der Connection: oracle.ucp.UniversalConnectionPoolException: Connection kann nicht aus Datenquelle abgerufen werden: java.sql.SQLException: ORA-01017: Benutzername/Kennwort ungültig; Anmeldung abgelehnt 
    at oracle.ucp.util.UCPErrorHandler.newSQLException(UCPErrorHandler.java:488) 
    at oracle.ucp.util.UCPErrorHandler.throwSQLException(UCPErrorHandler.java:163) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1055) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:985) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:966) 
    at jdbctest.main(jdbctest.java:18) 
Caused by: oracle.ucp.UniversalConnectionPoolException: Connection kann nicht aus Datenquelle abgerufen werden: java.sql.SQLException: ORA-01017: Benutzername/Kennwort ungültig; Anmeldung abgelehnt 
    at oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:368) 
    at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:49) 
    at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:80) 
    at oracle.ucp.jdbc.DataSourceConnectionFactoryAdapter.createConnection(DataSourceConnectionFactoryAdapter.java:102) 
    at oracle.ucp.jdbc.oracle.OracleDataSourceConnectionFactoryAdapter.createConnection(OracleDataSourceConnectionFactoryAdapter.java:82) 
    at oracle.ucp.common.UniversalConnectionPoolImpl$UniversalConnectionPoolInternal.createOnePooledConnectionInternal(UniversalConnectionPoolImpl.java:1776) 
    at oracle.ucp.common.UniversalConnectionPoolImpl$UniversalConnectionPoolInternal.access$600(UniversalConnectionPoolImpl.java:1612) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.createOnePooledConnection(UniversalConnectionPoolImpl.java:588) 
    at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.createOnePooledConnection(OracleJDBCConnectionPool.java:170) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionWithoutCountingRequests(UniversalConnectionPoolImpl.java:354) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionAndValidate(UniversalConnectionPoolImpl.java:167) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnection(UniversalConnectionPoolImpl.java:148) 
    at oracle.ucp.jdbc.JDBCConnectionPool.borrowConnection(JDBCConnectionPool.java:166) 
    at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.borrowConnection(OracleJDBCConnectionPool.java:1441) 
    at oracle.ucp.jdbc.oracle.OracleConnectionConnectionPool.borrowConnection(OracleConnectionConnectionPool.java:82) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1043) 
    ... 3 more 

JDBC 12.1 TNSALIASWITHOUTDOTS

Oracle 12.1.0.1.0 JDBC 4.1 compiled with JDK7 on Thu_Apr_04_15:09:24_PDT_2013 
#Default Connection Properties Resource 
#Mon Apr 14 09:30:42 CEST 2014 
Opening connection... 
Exception in thread "main" java.sql.SQLException: Exception beim Abrufen der Connection: oracle.ucp.UniversalConnectionPoolException: Connection kann nicht aus Datenquelle abgerufen werden: java.sql.SQLException: ORA-01017: Benutzername/Kennwort ungültig; Anmeldung abgelehnt 
    at oracle.ucp.util.UCPErrorHandler.newSQLException(UCPErrorHandler.java:488) 
    at oracle.ucp.util.UCPErrorHandler.throwSQLException(UCPErrorHandler.java:163) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1055) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:985) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:966) 
    at jdbctest.main(jdbctest.java:18) 
Caused by: oracle.ucp.UniversalConnectionPoolException: Connection kann nicht aus Datenquelle abgerufen werden: java.sql.SQLException: ORA-01017: Benutzername/Kennwort ungültig; Anmeldung abgelehnt 
    at oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:368) 
    at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:49) 
    at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:80) 
    at oracle.ucp.jdbc.DataSourceConnectionFactoryAdapter.createConnection(DataSourceConnectionFactoryAdapter.java:102) 
    at oracle.ucp.jdbc.oracle.OracleDataSourceConnectionFactoryAdapter.createConnection(OracleDataSourceConnectionFactoryAdapter.java:82) 
    at oracle.ucp.common.UniversalConnectionPoolImpl$UniversalConnectionPoolInternal.createOnePooledConnectionInternal(UniversalConnectionPoolImpl.java:1776) 
    at oracle.ucp.common.UniversalConnectionPoolImpl$UniversalConnectionPoolInternal.access$600(UniversalConnectionPoolImpl.java:1612) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.createOnePooledConnection(UniversalConnectionPoolImpl.java:588) 
    at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.createOnePooledConnection(OracleJDBCConnectionPool.java:170) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionWithoutCountingRequests(UniversalConnectionPoolImpl.java:354) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionAndValidate(UniversalConnectionPoolImpl.java:167) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnection(UniversalConnectionPoolImpl.java:148) 
    at oracle.ucp.jdbc.JDBCConnectionPool.borrowConnection(JDBCConnectionPool.java:166) 
    at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.borrowConnection(OracleJDBCConnectionPool.java:1441) 
    at oracle.ucp.jdbc.oracle.OracleConnectionConnectionPool.borrowConnection(OracleConnectionConnectionPool.java:82) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1043) 
    ... 3 more 

JDBC 12.1 TNSALIAS.WITH.DOTS

Oracle 12.1.0.1.0 JDBC 4.1 compiled with JDK7 on Thu_Apr_04_15:09:24_PDT_2013 
#Default Connection Properties Resource 
#Mon Apr 14 09:31:46 CEST 2014 
Opening connection... 
Exception in thread "main" java.sql.SQLException: Exception beim Abrufen der Connection: oracle.ucp.UniversalConnectionPoolException: Connection kann nicht aus Datenquelle abgerufen werden: java.sql.SQLRecoverableException: I/O-Fehler: Invalid connection string format, a valid format is: "host:port:sid" 
    at oracle.ucp.util.UCPErrorHandler.newSQLException(UCPErrorHandler.java:488) 
    at oracle.ucp.util.UCPErrorHandler.throwSQLException(UCPErrorHandler.java:163) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1055) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:985) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:966) 
    at jdbctest.main(jdbctest.java:18) 
Caused by: oracle.ucp.UniversalConnectionPoolException: Connection kann nicht aus Datenquelle abgerufen werden: java.sql.SQLRecoverableException: I/O-Fehler: Invalid connection string format, a valid format is: "host:port:sid" 
    at oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:368) 
    at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:49) 
    at oracle.ucp.util.UCPErrorHandler.throwUniversalConnectionPoolException(UCPErrorHandler.java:80) 
    at oracle.ucp.jdbc.DataSourceConnectionFactoryAdapter.createConnection(DataSourceConnectionFactoryAdapter.java:102) 
    at oracle.ucp.jdbc.oracle.OracleDataSourceConnectionFactoryAdapter.createConnection(OracleDataSourceConnectionFactoryAdapter.java:82) 
    at oracle.ucp.common.UniversalConnectionPoolImpl$UniversalConnectionPoolInternal.createOnePooledConnectionInternal(UniversalConnectionPoolImpl.java:1776) 
    at oracle.ucp.common.UniversalConnectionPoolImpl$UniversalConnectionPoolInternal.access$600(UniversalConnectionPoolImpl.java:1612) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.createOnePooledConnection(UniversalConnectionPoolImpl.java:588) 
    at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.createOnePooledConnection(OracleJDBCConnectionPool.java:170) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionWithoutCountingRequests(UniversalConnectionPoolImpl.java:354) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnectionAndValidate(UniversalConnectionPoolImpl.java:167) 
    at oracle.ucp.common.UniversalConnectionPoolImpl.borrowConnection(UniversalConnectionPoolImpl.java:148) 
    at oracle.ucp.jdbc.JDBCConnectionPool.borrowConnection(JDBCConnectionPool.java:166) 
    at oracle.ucp.jdbc.oracle.OracleJDBCConnectionPool.borrowConnection(OracleJDBCConnectionPool.java:1441) 
    at oracle.ucp.jdbc.oracle.OracleConnectionConnectionPool.borrowConnection(OracleConnectionConnectionPool.java:82) 
    at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:1043) 
    ... 3 more 

對於那些誰也不知道德國,ORA-01017的手段「無效的用戶名/密碼」

這意味着TNS Alias中除點12.1以外的每個組合都能夠連接t到數據庫。有什麼建議麼?

+0

您正在記錄一些信息,但是您從未發佈過這些日誌文件,以及setURL命令中使用的tns名稱別名如何定義。另外,查看偵聽器日誌文件可能會有所幫助。 – steve

回答

2

我們發現這是ojdbc驅動程序11.2.0.4及更高版本中的一個錯誤。我們將在oracle上創建一個bugreport。

解決方法是在名稱中使用不含點的標記。

+0

Oracle用12.1.0.2修正了這個問題。現在支持TNS入口別名內的點。 –