Spring Boot / Oracle / Java error : Could not get JDBC Connection results in Connection timed out

Refresh

April 2019

Views

826 time

1

The system I am working with has the following (I am using Spring Boot)

I am getting an error when starting an application using the following:

Caused by: 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) ~[spring-jdbc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:326) ~[spring-jdbc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    ... 61 common frames omitted

because of this, I get a java.net.ConnectException: Connection timed out: connect

Below is other information.

Why am I getting this error? The code sees the connection.url - but - it says that it can't work with it. As far as I can tell, the syntax is correct. How can I fix this?

TIA

the pom.xml file

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ccinrest</groupId>
    <artifactId>BackEndRestFunctionality</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>SpringBootErrorHandlingDemoy</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
    </parent>

    <repositories>
        <repository>
            <id>maven.oracle.com</id>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <url>https://maven.oracle.com</url>
            <layout>default</layout>
        </repository>

    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>maven.oracle.com</id>
            <url>https://maven.oracle.com</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-ext</artifactId>
            <version>1.7.25</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <!-- <version>5.0.0.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            $NO-MVN-MAN-VER$
            <artifactId>spring-security-config</artifactId>
            <!-- <version>5.0.0.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <!-- <version>5.0.0.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <!-- <version>1.0.0.RELEASE</version> -->
        </dependency>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.8.0</version>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>12.2.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>

        </dependency>
    </dependencies>

</project>

The application.properties file looks like the following:

spring.datasource.url=jdbc:oracle:thin:@//localhost:1521/DSV
spring.datasource.username=<my_id>
spring.datasource.password=<my_password>
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery="SELECT 1"

# ===============================
# = JPA / HIBERNATE
# ===============================
# Show or not log for each sql query
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update): with "create-drop" the database
# schema will be automatically created afresh for every start of application
spring.jpa.hibernate.ddl-auto=create-drop
# Naming strategy
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
#hibernate config
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

Error Log

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.4.RELEASE)

2018-01-24 19:25:06.507  INFO 12076 --- [           main] ccinrest.App                             : Starting App on DESKTOP-8EFRPQF with PID 12076 (C:\WORK\Test\SpringBootErrorHandlingDemo\target\classes started by dgmufasa in C:\WORK\Test\SpringBootErrorHandlingDemo)
2018-01-24 19:25:06.511  INFO 12076 --- [           main] ccinrest.App                             : No active profile set, falling back to default profiles: default
2018-01-24 19:25:06.629  INFO 12076 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]64d7f7e0: startup date [Wed Jan 24 19:25:06 CST 2018]; root of context hierarchy
2018-01-24 19:25:09.949  INFO 12076 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-01-24 19:25:09.968  INFO 12076 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-01-24 19:25:09.973  INFO 12076 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.15
2018-01-24 19:25:10.183  INFO 12076 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-01-24 19:25:10.183  INFO 12076 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3559 ms
2018-01-24 19:25:10.523  INFO 12076 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-24 19:25:10.524  INFO 12076 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-01-24 19:25:10.524  INFO 12076 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-01-24 19:25:10.524  INFO 12076 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-01-24 19:25:10.526  INFO 12076 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-01-24 19:25:10.526  INFO 12076 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-01-24 19:25:33.725 ERROR 12076 --- [           main] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:774) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:688) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:691) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) ~[tomcat-jdbc-8.5.15.jar:na]
    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) ~[tomcat-jdbc-8.5.15.jar:na]
    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735) [tomcat-jdbc-8.5.15.jar:na]
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667) [tomcat-jdbc-8.5.15.jar:na]
    at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482) [tomcat-jdbc-8.5.15.jar:na]
    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154) [tomcat-jdbc-8.5.15.jar:na]
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) [tomcat-jdbc-8.5.15.jar:na]
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) [tomcat-jdbc-8.5.15.jar:na]
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) [tomcat-jdbc-8.5.15.jar:na]
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) [spring-jdbc-4.3.9.RELEASE.jar:4.3.9.RELEASE]

[.. snip ...]

Caused by: java.net.ConnectException: Connection timed out: connect
    at sun.nio.ch.Net.connect0(Native Method) ~[na:1.8.0_161]
    at sun.nio.ch.Net.connect(Unknown Source) ~[na:1.8.0_161]
    at sun.nio.ch.Net.connect(Unknown Source) ~[na:1.8.0_161]
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source) ~[na:1.8.0_161]
    at java.nio.channels.SocketChannel.open(Unknown Source) ~[na:1.8.0_161]
    at oracle.net.nt.TimeoutSocketChannel.<init>(TimeoutSocketChannel.java:81) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:169) ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]
    ... 57 common frames omitted

0 answers