Reputation: 31
My application use many datasources (postgreSQL, Sybase) I try to add one Oracle datasource
Application.properties
rocbis.datasource.prd.driver.class-name=oracle.jdbc.driver.OracleDriver
rocbis.datasource.prd.jdbc-url=jdbc:oracle:thin:@<host>:1521:<dbname>
rocbis.datasource.prd.username=<username>
rocbis.datasource.prd.password=<password>
host, dbname, username & password have been obfuscated...
Configuration class
@Bean(name = "rocbisDatasourcePRD")
@ConfigurationProperties(prefix = "rocbis.datasource.prd")
public DataSource rocbisDataSourcePRD() {
return DataSourceBuilder.create().build();
}
@Bean(name = "rocbisJDBCTemplatePRD")
public JdbcTemplate rocbisJdbcTemplatePRD(@Qualifier("rocbisDatasourcePRD") DataSource ds) {
return new JdbcTemplate(ds);
}
and POM.xml
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.6.0.0</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ucp</artifactId>
<version>19.6.0.0</version>
</dependency>
When Springboot starts I have the following error :
Caused by: java.lang.RuntimeException: Failed to get driver instance
for jdbcUrl=jdbc:oracle:thin:@<host>:1521:<dbname> at com.zaxxer.hikari.util.DriverDataSource.<init>DriverDataSource.java:112)
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:336)
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:109)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
at config.DatasourceConfiguration.rocbisJdbcTemplatePRD(DatasourceConfiguration.java:446)
at config.DatasourceConfiguration$$EnhancerBySpringCGLIB$$1cdc8e91.CGLIB$rocbisJdbcTemplatePRD$59(<generated>)
at config.DatasourceConfiguration$$EnhancerBySpringCGLIB$$1cdc8e91$$FastClassBySpringCGLIB$$9002c681.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
at config.DatasourceConfiguration$$EnhancerBySpringCGLIB$$1cdc8e91.rocbisJdbcTemplatePRD(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 64 common frames omitted
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:104)
... 79 common frames omitted
- org.springframework.boot.SpringApplication
I tried :
driver-class-name instead of driver.class-name
oracle.jdbc.driver.OracleDriver instead of oracle.jdbc.OracleDriver
Any idea ? Thanks
Upvotes: 0
Views: 9495
Reputation: 5063
I have solved the like below in my j2ee project. You may follow
I have added below lib:
1. ojdbc8-19.3.0.0.jar
2. HikariCP-3.1.0.jar
3. slf4j.jdk14-1.6.1.jar
4. slf4j-api-1.7.2.jar
Here is the connection I have used below:
Connection con = null;
try {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:oracle:thin:@localhost:1521/mydb");
config.setUsername("myuser");
config.setPassword("mypass");
config.setMaximumPoolSize(2000);
config.setAutoCommit(false);
config.setMinimumIdle(100);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.setDriverClassName("oracle.jdbc.OracleDriver");
HikariDataSource dataSource = new HikariDataSource(config);
con = dataSource.getConnection();
} catch (SQLException ex) {
ex.printStackTrace();
}
Note: Don't forget to add oracle.jdbc.OracleDriver name
Upvotes: 0
Reputation: 121
Use oracle.jdbc.OracleDriver
instead of oracle.jdbc.driver.OracleDriver
Below configurations worked for me with Oracle
pom.xml
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
bootstrap.properties
spring.datasource.url=jdbc:oracle:thin:@<host>:<port>:<service>
spring.datasource.username=<username>
spring.datasource.password=<password>
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
Upvotes: 3