title: Could not get JDBC Connection; nested exception is java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
body: <p>I am trying to execute a spring logic which will create a jdbc table.
  However on executing the code I am getting the following error.</p>
  
  <pre><code>Jun 18, 2017 4:15:19 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  INFO: Loading XML bean definitions from class path resource [springConfig.xml]
  Jun 18, 2017 4:15:19 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
  INFO: Loaded JDBC driver: oracle.jdbc.driver.OracleDriver
  Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
      at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:394)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:443)
      at springExample.JDBCCreateTableTemplate.createTable(JDBCCreateTableTemplate.java:18)
      at springExample.ClientLogic.main(ClientLogic.java:19)
  Caused by: 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:664)
      at java.sql.DriverManager.getConnection(DriverManager.java:208)
      at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
      at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
      at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196)
      at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159)
      at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
      at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
      ... 4 more
  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.NSProtocol.connect(NSProtocol.java:229)
      at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
      ... 16 more
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:589)
      at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:162)
      at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
      at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:411)
      ... 21 more
  </code></pre>
  
  <p>This is my springConfig.xml file.</p>
  
  <pre><code>&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
  "http://www.springframework.org/dtd/spring-beans-2.0.dtd"&gt;
  
  &lt;beans&gt;
  
      &lt;bean id="id1"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;
          &lt;property name="url" value="jdbc:oracle:thin:@localhost:1521:XE" /&gt;
          &lt;property name="username" value="admin" /&gt;
          &lt;property name="password" value="admin" /&gt;
      &lt;/bean&gt;
      &lt;bean id="id2" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
          &lt;constructor-arg&gt;
              &lt;ref bean="id1" /&gt;
          &lt;/constructor-arg&gt;
      &lt;/bean&gt;
      &lt;bean id="id3" class="springExample.JDBCCreateTableTemplate"&gt;
          &lt;property name="jdbcTemplate"&gt;
              &lt;ref bean="id2" /&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>This is my JDBCCreateTemplate file</p>
  
  <pre><code>    package springExample;
  
  import org.springframework.jdbc.core.JdbcTemplate;
  
  public class JDBCCreateTableTemplate {
  
      JdbcTemplate jdbcTemplate;
  
      public JdbcTemplate getJdbcTemplate() {
          return jdbcTemplate;
      }
  
      public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
          this.jdbcTemplate = jdbcTemplate;
      }
  
      void createTable(){
          jdbcTemplate.execute("create table springtest(sno number(3), sname varchar(10))");
          System.out.println("Table created");
      }
  }
  </code></pre>
  
  <p>And this is my ClientLogic file</p>
  
  <pre><code>package springExample;
  
  import org.springframework.beans.factory.BeanFactory;
  import org.springframework.beans.factory.xml.XmlBeanFactory;
  import org.springframework.core.io.ClassPathResource;
  import org.springframework.core.io.Resource;
  
  public class ClientLogic {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          Resource res = new ClassPathResource("springConfig.xml");
          BeanFactory beanFactory = new XmlBeanFactory(res);
  
          JDBCCreateTableTemplate jdbcCreateTableTemplate = (JDBCCreateTableTemplate) beanFactory.getBean("id3");
          jdbcCreateTableTemplate.createTable();
  
      }
  
  }
  </code></pre>