Reputation: 1873
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.
Upvotes: 0
Views: 3975
Reputation: 13571
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
Upvotes: 0
Reputation: 176
It looks like you are missing "//" after @ in your database url. Try with
oracle.url=jdbc:oracle:thin:@//abc.def.com:1521:XE
Upvotes: 1