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.

2 Answers 2

1

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

oracle.url=jdbc:oracle:thin:@//abc.def.com:1521:XE
Sign up to request clarification or add additional context in comments.

1 Comment

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
0

I believe Oracle XE will run as a service by default as opposed to a SID. Consider changing your url

from

jdbc:oracle:thin:@abc.def.com:1521:XE

to

jdbc:oracle:thin:@//localhost:1521/XE

template:

@//host_name:port_number/service_name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.