Note that there are some explanatory texts on larger screens.

plurals
  1. POConnection to Oracle from Java unreliable
    text
    copied!<p>I'm new to Java and trying to setup a connection to an Oracle database from a redhat Linux machine. I've got the connection working and can execute a simple sql script but the connection only works approx. 1 in 3 times. The error it gives and the code is below. It is quite possible this is an issue with our network but I would like to have a bit more knowledge before I raise a support case. Does anyone know why the error says "Name or service not known" for ssdb0255n21-oravip when "someserver" is what is specified in the connection?</p> <pre><code>Exception in thread "main" java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673) at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:715) at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:385) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:187) at OracleTest.main(OracleTest.java:19) Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:445) at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:464) at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594) at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:214) at oracle.net.ns.NSProtocol.connect(NSProtocol.java:263) at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486) ... 7 more Caused by: java.net.UnknownHostException: ssdb0255n21-oravip: Name or service not known at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:894) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1286) at java.net.InetAddress.getAllByName0(InetAddress.java:1239) at java.net.InetAddress.getAllByName(InetAddress.java:1155) at java.net.InetAddress.getAllByName(InetAddress.java:1091) at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:117) at oracle.net.nt.ConnOption.connect(ConnOption.java:133) at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:411) ... 13 more </code></pre> <p>The code I am using is this</p> <pre><code>import java.sql.*; import java.util.Properties; public class OracleTest { public static void main(String[] args) throws SQLException { String url = "jdbc:oracle:thin:@ldaps://someserver:3131/ODBF2_BLOOD_P_S_B_001,cn=OracleContext,dc=in,dc=companyname,dc=com,dc=au"; //properties for creating connection to Oracle database Properties props = new Properties(); props.setProperty("user", "xxx"); props.setProperty("password", "xxxx"); //creating connection to Oracle database using JDBC System.out.println(DriverManager.getLoginTimeout()); Connection conn = DriverManager.getConnection(url,props); String sql ="select sysdate as current_day from dual"; //creating PreparedStatement object to execute query PreparedStatement preStatement = conn.prepareStatement(sql); ResultSet result = preStatement.executeQuery(); while(result.next()) { System.out.println("Current Date from Oracle : " + result.getString("current_day")); } System.out.println("done"); } } </code></pre> <p>I have ORACLE_HOME set to /usr/lib/oracle/10.2.0.5/client64/ and have created ldap.ora and sqlnet.ora files in /usr/lib/oracle/10.2.0.5/client64/network/admin. Contents of these are:</p> <p>sqlnet.ora</p> <pre><code>NAMES.DIRECTORY_PATH = (LDAP,TNSNAMES) </code></pre> <p>ldap.ora</p> <pre><code>DIRECTORY_SERVERS = (OID.GLB.IN.companyname.COM.AU::3131) DEFAULT_ADMIN_CONTEXT = "dc=in,dc=companyname,dc=com,dc=au" DIRECTORY_SERVER_TYPE = OID </code></pre> <p>It appears to have created tnsnames.ora itself</p> <pre><code>ORA11 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ORA11) ) ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload