0

In my spring boot application while trying to connect to the oracle database i get the following exception

    java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL
    at oracle.jdbc.pool.OracleDataSource.makeURL(OracleDataSource.java:1536)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:214)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:184)
    at com.pravaa.apex.MainController.getEmployees(MainController.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

My properties file is as below:

    #Oracle connection
    oracle.username=a_test_erd
    oracle.password=somepassword
    oracle.url=jdbc:oracle:thin:@abc.def.com:1521:XE

My configuration class is as below:

import java.sql.SQLException;

import javax.sql.DataSource;
import javax.validation.constraints.NotNull;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import oracle.jdbc.pool.OracleDataSource;

@Configuration
@ConfigurationProperties("oracle")
public class OracleConfiguration {
    @NotNull
    private String username;

    @NotNull
    private String password;

    @NotNull
    private String url;

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Bean
    DataSource dataSource() throws SQLException {
        OracleDataSource dataSource = new OracleDataSource();
        dataSource.setUser(username);
        dataSource.setPassword(password);
        dataSource.setURL(url);
        dataSource.setImplicitCachingEnabled(true);
        dataSource.setFastConnectionFailoverEnabled(true);
        return dataSource;
    }
}

I tried the solutions provided here Invalid Oracle URL specified: OracleDataSource.makeURL and few other posts. Still have the same issue. Can someone help.

S.A.Norton Stanley
  • 1,833
  • 3
  • 23
  • 37

1 Answers1

1

It looks like you are missing "//" after @ in your database url. Try with

oracle.url=jdbc:oracle:thin:@//abc.def.com:1521:XE
Jawa
  • 176
  • 1
  • 7
  • i tried the same oracle.url=jdbc:oracle:thin:@//abc.def.com:1521:XE as suggested still get 2018-04-14 21:25:11.779 INFO 14274 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 13 ms java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL – S.A.Norton Stanley Apr 14 '18 at 15:57