0

I have installed Oracle Weblogic Server in my local machine Windows 7. Now I am trying to create a new data source.

I have a database which is hosted in a different location. I have the connection properties with which I could successfully do a Test Connection from SQL_Developer client in my machine.

Database connection details :

> URL : jdbc:oracle:thin:@hostname:port:DB_Name
> 
> Driver Class : oracle.jdbc.xa.client.OracleXADataSource

However when I am using the same connection properties in the weblogic server to connect to the same database it is throwing the below error :

> Connection test failed.
IO Error: The Network Adapter could not establish the connection
<br/>oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:458)
<br/>oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
<br/>oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
<br/>oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
<br/>oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
<br/>oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280)
<br/>oracle.jdbc.xa.client.OracleXADataSource.getPooledConnection(OracleXADataSource.java:469)
<br/>oracle.jdbc.xa.client.OracleXADataSource.getXAConnection(OracleXADataSource.java:156)
<br/>oracle.jdbc.xa.client.OracleXADataSource.getXAConnection(OracleXADataSource.java:101)
<br/>weblogic.jdbc.common.internal.DataSourceUtil.testConnection(DataSourceUtil.java:314)
<br/>com.bea.console.utils.jdbc.JDBCUtils.testConnection(JDBCUtils.java:734)
<br/>com.bea.console.actions.jdbc.datasources.createjdbcdatasource.CreateJDBCDataSource.testConnectionConfiguration(CreateJDBCDataSource.java:474)
<br/>sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
<br/>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
<br/>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
<br/>java.lang.reflect.Method.invoke(Method.java:606)
<br/>org.apache.beehive.netui.pageflow.FlowController.invokeActionMethod(FlowController.java:870)
<br/>org.apache.beehive.netui.pageflow.FlowController.getActionMethodForward(FlowController.java:809)
<br/>org.apache.beehive.netui.pageflow.FlowController.internalExecute(FlowController.java:478)
<br/>org.apache.beehive.netui.pageflow.PageFlowController.internalExecute(PageFlowController.java:306)

Below is the stack trace that I am getting over the console :

> Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:392)
    at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:434)
    at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:687)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:247)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320)

Continued to the below :

> Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:150)
    at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:370)

I am having the below versions in my machine :

>    JDK : 1.7
>    Weblogic : 10.3.6
>    ojdbc6.jar (part of weblogic installation, no extra 3rd party driver being used)

Please let me know what I am missing out during the data source configurations in weblogic server. Please help me resolve the issue.

Som
  • 1,522
  • 1
  • 15
  • 48
  • have you seen https://stackoverflow.com/questions/6876266/java-net-connectexception-connection-refused ? – thatjeffsmith May 14 '18 at 14:27
  • You can check out the blog (https://blogs.oracle.com/dev2dev/create-and-deploy-a-java-servlet-using-weblogic-server-wls) for creating the datasource and also, the github code (https://github.com/oracle/oracle-db-examples/tree/master/java/jdbc/WebLogicServer_Servlet) – Nirmala May 14 '18 at 22:58
  • no help :( The problem is very strange. Initially I thought it to be firewall issue but checked the traffic which are getting blocked but it is not listed there. How come my SQL developer is able to connect to the database and my Weblogic server could not ? – Som May 15 '18 at 07:55

1 Answers1

0

After looking out for the errors, finally understood what is the actual problem.

Java 7 by default uses IPv6 protocol. So I have enforced java to use the IPv4 instead of IPv6.

Solution :

Open the domain folder where weblogic has been installed. By default the name is "base_domain" if you donot change it during installation. So go inside "base_domain/bin" and open the file "setDomainEnv.cmd" for editing (For Linux machine use the file setDomainEnv.sh) and then look for the below line :

set JAVA_OPTIONS=%JAVA_OPTIONS%

Just add a space after that and add the following : 
-Djava.net.preferIPv4Stack=true

So your final line should look like : set JAVA_OPTIONS=%JAVA_OPTIONS% -Djava.net.preferIPv4Stack=true

and save the file and come out. Restart your weblogic server and test the data source.

Main thing is the parameter : -Djava.net.preferIPv4Stack=true

You can add it in your environment variables, that should work. However, if that doesn't work then you can follow what I have done above. Hope this helps !

Som
  • 1,522
  • 1
  • 15
  • 48