Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database Connectivity issues with Oracle Drivers

 
santosh batta
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm new to JDBC & I'm trying to connect to oracle database using traditional oracle drivers. My program works fine & was able to connect and run the queries. While testing my code, after sometime, I got database connection failure due to "The Network Adapter could not establish the connection". Below is the stack trace, what I got.

2014/07/24 14:22:51:461 MDT [TRACE] DatabaseManager - Entering: com.bcn.batchstats.util.DatabaseManager Method: openConnection
2014/07/24 14:22:51:787 MDT [ERROR] DatabaseManager - Error opening Database connection during maxRetries: jdbcracle:thin:@<hostname>:<port>:<SID> <java.sql.SQLException: The Network Adapter could not establish the connection>java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(DriverManager.java:572)
at java.sql.DriverManager.getConnection(DriverManager.java:196)
at com.org.batchstats.util.DatabaseManager.openConnection(Unknown Source)
at com.org.batchstats.util.AgentConfigurationUtil.fetchAgentConfiguration(Unknown Source)
at com.org.batchstats.util.AgentConfigurationUtil.loadStatsCollectors(Unknown Source)
at com.org.batchstats.StatsAgent.createCollectorThreadList(Unknown Source)
at com.org.batchstats.StatsAgent.main(Unknown Source)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:237)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 11 more
Caused by: java.net.UnknownHostException: <hostname>: <hostname>
at java.net.InetAddress.getAllByName0(InetAddress.java:1249)
at java.net.InetAddress.getAllByName(InetAddress.java:1176)
at java.net.InetAddress.getAllByName(InetAddress.java:1099)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:114)
at oracle.net.nt.ConnOption.connect(ConnOption.java:123)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:337)
... 16 more

2014/07/24 14:22:51:789 MDT [TRACE] DatabaseManager - Exiting: com.org.batchstats.util.DatabaseManager Method: openConnection
2014/07/24 14:22:52:291 MDT [FATAL] DatabaseManager - DB connection == null: java.sql.SQLException: The Network Adapter could not establish the connection.

I didn't touch the database part while modifying the code. Its just a date utility that I've worked on & not sure what caused the problem, given that it was working fine after my changes as well. Moreover, I'm able to connect to the same database using SQL developer tool. I check the properties & all the properties are similar. Please help me.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you specifying the connection parameters?
 
santosh batta
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Thanks for your response. Below is my piece of code I use to connect to database.



Below is the stack trace where I get correct jdbc URL.

2014/07/24 14:22:49:888 MDT [DEBUG] DatabaseManager - driverClassname Property: com.org.batchstats.util.DatabaseManager Method: DatabaseManager Constructor oracle.jdbc.driver.OracleDriver
2014/07/24 14:22:49:889 MDT [DEBUG] DatabaseManager - jdbcUrl Property: com.org.batchstats.util.DatabaseManager Method: DatabaseManager Constructor jdbcracle:thin:@<hostname>:<port>:<database name>

Let me know, if you need anymore info.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the value of "jdbcUrl"? Not what you think it should be, but its actual value. Print it out when you try to make the connection.
 
santosh batta
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the stack trace, I provided in my post.. I've printed the jdbc URL. I check with SQL developer & its working fine. I'm able to connect to the database. So, I believe there is nothing wrong with the jbdc URL. Did I miss something?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean "jdbc:oracle:thin:@<hostname>:<port>:<databasename>" is the actual value you're using? In that case it's no wonder it's not working - you need to provide valid values for hostname, port and databasename.
 
santosh batta
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Thats not the actual values. Anyway thanks for your response. I figured out that the issue is with the hostname. Thats no more in use & hence is not responding and my attempt to connect to it fails.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic