Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- #Oracle connection
- oracle.username=a_test_erd
- oracle.password=somepassword
- oracle.url=jdbc:oracle:thin:@abc.def.com:1521:XE
- 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;
- }
- }
Add Comment
Please, Sign In to add comment