将TNS别名与ojdbc 12.1一起使用

时间:2014-04-11 10:36:10

标签: java oracle ojdbc oracle12c ucp

我正在开发一个需要访问Oracle数据库的java应用程序。到目前为止,我已经使用了ojdbc6驱动程序没有任何问题。现在我们将数据库切换到Oracle 12c,所以我想使用更新的JDBC驱动程序。

这是代码

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之外的每个组合都能够连接到数据库。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

我们发现这是ojdbc驱动程序11.2.0.4及更高版本中的错误。我们将在oracle创建一个bug报告。

解决方法是使用名称中没有点的tnsaliases。