Using TNS Alias with ojdbc 12.1



我正在删除一个需要访问Oracle数据库的java应用程序。到目前为止,我使用ojdbc6驱动程序没有任何问题。现在我们将数据库切换到Oracle12c,所以我想使用更新的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个tnsaliase)的输出jdbc 11.2,TNSALIAWITHOUTDOTS

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 TNSALIAWITHOUTDOTS

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-0017的意思是"无效的用户名/密码"

这意味着TNS Alias中除了12.1中带点之外的所有组合都可以连接到数据库。有什么建议吗?

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

解决方法是使用名称中不带点的tnsalinase。

相关内容

  • 没有找到相关文章

最新更新