title: java.sql.SQLException The Network Adapter could not establish the connection
body: <p>I have a java/hibernate/jpa app that uses the following ojdbc driver (because of historical reasons, have to connect to an Oracle 10 DB). I am getting the following error message</p>
  
  <blockquote>
    <p>2017-09-16 13:36:02 WARN  o.s.b.a.orm.jpa.DatabaseLookup - Unable to
    determine jdbc url from datasource
    org.springframework.jdbc.support.MetaDataAccessException: Could not
    get Connection for extracting meta data; nested exception is
    org.springframework.jdbc.CannotGetJdbcConnectionException: Could not
    get JDBC Connection; nested exception is java.sql.SQLException: Io
    exception: The Network Adapter could not establish the connect</p>
  </blockquote>
  
  <p>Whenever I use the internal definition of the host (holding the DB - and not 127.0.0.1 loopback address), it works. Whenever I use the externally defined hostname, it does not work. </p>
  
  <p>When using the <strong>application.properties file</strong> the following connect string <em>DOES WORK</em> for the APP:</p>
  
  <blockquote>
    <p>spring.datasource.url=jdbc:oracle:thin:@<strong>internalhost</strong>:1527:DSM
    (ex: 192.x.x.x - 192.88.33.22 ) Pls note, I am NOT using 127.0.0.1
    (loopback address)</p>
  </blockquote>
  
  <p>When using the <strong>application.properties file</strong> the following connect string <em>DOES NOT WORK</em> for the APP:</p>
  
  <blockquote>
    <p>spring.datasource.url=jdbc:oracle:thin:@<strong>externalhost.com</strong>:1527:DSM
    (ex: 99.22.123.44)</p>
  </blockquote>
  
  <p>I run the following at the OS LEVEL - this test <em>DOES WORK</em> :</p>
  
  <blockquote>
    <p>sqlplus
    scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=externalhost.com)(PORT=1527))(CONNECT_DATA=(SERVICE_NAME=DSM)))</p>
  </blockquote>
  
  <p>I ran the following Java test (at OS LEVEL) and it <em>DOES WORK</em></p>
  
  <pre><code>import java.sql.DriverManager;
  import java.sql.Connection;
  import java.sql.SQLException;
  
  public class OracleJDBCExample {
      public static void main(String[] argv) {
          System.out.println("-------- Oracle JDBC Connection Testing ------");
          try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
              /*Class.forName("oracle.jdbc.OracleDriver");*/
  
          } catch (ClassNotFoundException e) {
              System.out.println("Where is your Oracle JDBC Driver?");
              e.printStackTrace();
              return;
          }
          System.out.println("Oracle JDBC Driver Registered!");
          Connection connection = null;
          try {
              connection = DriverManager.getConnection(
                      "jdbc:oracle:thin:@externalhost.com:1527:DSM", "scott", "tiger");              
          } catch (SQLException e) {
              System.out.println("Connection Failed! Check output console");
              e.printStackTrace();
              return;
          }
          if (connection != null) {
              System.out.println("You made it, take control your database now!");
          } else {
              System.out.println("Failed to make connection!");
          }
      }
  </code></pre>
  
  <p>How can I fix this problem?
  TIA</p>
  
  <p><strong>application.properties file</strong></p>
  
  <pre><code># Oracle settings
  spring.datasource.url=jdbc\:oracle\:thin\:@externalhost.com\:1527\:DSM  (ex: 99.22.123.44)
  spring.datasource.username=scott
  spring.datasource.password=tiger
  spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
  
  #thymeleaf
  spring.thymeleaf.cache=false
  </code></pre>
  
  <p><strong>Error received</strong></p>
  
  <pre><code> :: Spring Boot ::        (v1.5.4.RELEASE)
  
  2017-09-16 13:35:34 DEBUG o.s.w.c.s.StandardServletEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence
  2017-09-16 13:35:34 DEBUG o.s.w.c.s.StandardServletEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence
  2017-09-16 13:35:34 DEBUG o.s.w.c.s.StandardServletEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
  2017-09-16 13:35:34 DEBUG o.s.w.c.s.StandardServletEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
  2017-09-16 13:35:34 DEBUG o.s.w.c.s.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,systemProperties,systemEnvironment]
  2017-09-16 13:35:34 INFO  ccinfw.MainApplication - Starting MainApplication on kdclaptop with PID 17172 (C:\Users\dgmufasa\git\LocalCCINFieldworkServer\ccinfieldworkserver\target\classes started by dgmufasa in C:\Users\dgmufasa\git\LocalCCINFieldworkServer\ccinfieldworkserver)
  2017-09-16 13:35:34 INFO  ccinfw.MainApplication - No active profile set, falling back to default profiles: default
  2017-09-16 13:35:35 INFO  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@44616f65: startup date [Sat Sep 16 13:35:35 UTC 2017]; root of context hierarchy
  2017-09-16 13:35:38 DEBUG o.s.w.c.s.StandardServletEnvironment - Adding [applicationConfig: [classpath:/application.properties]] PropertySource with search precedence immediately lower than [applicationConfigurationProperties]
  2017-09-16 13:35:38 DEBUG o.s.w.c.s.StandardServletEnvironment - Removing [applicationConfigurationProperties] PropertySource
  2017-09-16 13:35:38 DEBUG o.s.w.c.s.StandardServletEnvironment - Removing [defaultProperties] PropertySource
  2017-09-16 13:35:39 INFO  o.s.b.c.e.t.TomcatEmbeddedServletContainer - Tomcat initialized with port(s): 8080 (http)
  2017-09-16 13:35:39 INFO  o.a.catalina.core.StandardService - Starting service [Tomcat]
  2017-09-16 13:35:39 INFO  o.a.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/8.5.15
  2017-09-16 13:35:39 INFO  o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
  2017-09-16 13:35:39 DEBUG o.s.web.context.ContextLoader - Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
  2017-09-16 13:35:39 INFO  o.s.web.context.ContextLoader - Root 
  
  [...snip ...]
  
  2017-09-16 13:35:39 INFO  o.s.b.w.s.FilterRegistrationBean - Mapping filter: 'webRequestLoggingFilter' to: [/*]
  2017-09-16 13:35:39 INFO  o.s.b.w.s.FilterRegistrationBean - Mapping filter: 'applicationContextIdFilter' to: [/*]
  2017-09-16 13:35:40 DEBUG o.s.w.c.s.StandardServletEnvironment - Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]
  2017-09-16 13:36:01 ERROR o.a.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
  java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:414)
      at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:165)
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
      at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310)
      at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.&lt;init&gt;(ConnectionPool.java:154)
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)
      at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
      at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
      at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:326)
      at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:366)
      at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72)
      at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139)
      at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105)
      at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$d97029fd.CGLIB$jpaVendorAdapter$5(&lt;generated&gt;)
      at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$d97029fd$$FastClassBySpringCGLIB$$be6e3771.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
      at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
      at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$d97029fd.jpaVendorAdapter(&lt;generated&gt;)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
      at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
      at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
      at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
      at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
      at ccinfw.MainApplication.main(MainApplication.java:19)
  2017-09-16 13:36:02 WARN  o.s.b.a.orm.jpa.DatabaseLookup - Unable to determine jdbc url from datasource
  org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
  </code></pre>
  
  <p><strong>Update (took out pom.xml def)</strong></p>
  
  <p>@Mark Rotteveel. Thanks for response SID = service-name. See below.</p>
  
  <pre><code>SQL&gt; show parameter service
  NAME                                 TYPE        VALUE
  ------------------------------------ ----------- ------------------------------
  service_names                        string      DSM
  </code></pre>
  
  <p>Also, note:</p>
  
  <pre><code>WORKS (Hibernate is doing the connection):
  spring.datasource.url=jdbc:oracle:thin:@internalhost:1527:DSM  
  internalhost example (192.167.1.xxx)
  
  DOES NOT WORK (Hibernate is doing the connection)
  spring.datasource.url=jdbc:oracle:thin:@externalhost.com:1527:DSM 
  externalhost.com example (92.34.144.88)
  
  DOES NOT WORK (Hibernate is doing the connection)
  spring.datasource.url=jdbc:oracle:thin:@//externalhost.com:1527/DSM 
  externalhost.com example (92.34.144.88)
  
  TEST AT OS LEVEL DOES WORK ( using externalhost.com as a HOST )
  sqlplus scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=externalhost.com)(PORT=1527))(CONNECT_DATA=(SERVICE_NAME=DSM)))
  
  TEST AT OS LEVEL USING **PLAIN JAVA CODE** - in other words NO Hibernate - DOES WORK ( using externalhost.com as a HOST )
  (see above)
  </code></pre>
  
  <p><strong>How can one do a more detailed tracing?</strong> </p>
  
  <p>At first I thought it was a networking error - but - I am still able to connect to the DB using regular JAVA and also connecting at the OS level. Again, these work. It does not seem to work when doing it with the Hibernate connection.</p>
  
  <p>However using Hibernate on internal (ex: 192.168.1.xxx) address works.
  Using Hibernate for the exact same machine (but just using the external address - ex: 93.23.44.22 ) does not work.</p>