mattobob mattobob -3 years ago 230
YAML Question

Failed to get driver instance for oracle

I’m trying to connect to my oracle database, I’m using a spring boot configuration together with YAML file, I’ve configured jdbc in pom and jpa, but it still fails to connect.

I’ve tried many different configuration for the url:

1) jdbcUrl=jdbc:oracle:thin://test.test.test:1521

2) jdbcUrl=jdbc:oracle:thin@test.test.test:1521

3) jdbcUrl=jdbc:oracle://test.test.test:1521

4) jdbcUrl=jdbc:oracle@test.test.test:1521


here my application.yml

spring:
profiles: test
datasource:
onlineterminierung:
url: jdbc:oracle: jdbc:oracle:thin://test.test.test:1521
database: test
username: test
password: test
driverClassName: oracle.jdbc.driver.OracleDriver
defaultSchema:
maxPoolSize: 20
hibernate:
hbm2ddl.method: update
show_sql: false
format_sql: true
dialect: org.hibernate.dialect.Oracle10gDialect


and here the DataSource bean:

/*
* Configure HikariCP pooled DataSource.
*/
@Bean
public DataSource dataSource() {
DataSourceProperties dataSourceProperties = dataSourceProperties();
HikariDataSource dataSource = (HikariDataSource) DataSourceBuilder.create(dataSourceProperties.getClassLoader())
.driverClassName(dataSourceProperties.getDriverClassName()).url(dataSourceProperties.getUrl()).username(dataSourceProperties.getUsername())
.password(dataSourceProperties.getPassword()).type(HikariDataSource.class).build();
dataSource.setMaximumPoolSize(maxPoolSize);
return dataSource;
}


here the pom:

<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
<scope>test</scope>
</dependency>


here the stack:

HHH000342: Could not obtain connection to query metadata : Failed to get driver instance for jdbcUrl=jdbc:oracle:thin://test.test.test:1521
Unable to build Hibernate SessionFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:oracle:thin://test.test.test:1521
Caused by: java.sql.SQLException: No suitable driver


Some idea?

Answer Source

Syntax:

jdbc:oracle:thin:@host:port:db","usname","pwd"

@Autowired
    DataSource dataSource;



@Bean(name = "dataSource")
public DriverManagerDataSource dataSource() {
    DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
    driverManagerDataSource.setDriverClassName("oracle.jdbc.OracleDriver");
    driverManagerDataSource.setUrl("jdbc:oracle:thin:@hostname:1521/dbname");
    driverManagerDataSource.setUsername("uname");
    driverManagerDataSource.setConnectionProperties(getadditionalJpaProperties());
    driverManagerDataSource.setPassword("password");
    return driverManagerDataSource;
}

Properties getadditionalJpaProperties() {
    Properties properties = new Properties();
    // properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
    properties.setProperty("hibernate.show_sql", "true");

    return properties;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download