我正在尝试连接到我的oracle数据库,我正在使用Spring引导配置和YAML文件,我已经在pom和jpa中配置了jdbc,但它仍然无法连接。
我为网址尝试了很多不同的配置:
-- 42% opaque
translucent = Css.opacity (Css.num 0.42)
这里是我的application.yml
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
这里是DataSource bean:
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
这里是pom:
/*
* 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;
}
这是堆栈:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
<scope>test</scope>
</dependency>
有些想法?
答案 0 :(得分:3)
语法:
JDBC:预言:瘦:@host:端口:分贝&#34;&#34; usname&#34;&#34; PWD&#34;
@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;
}
答案 1 :(得分:2)
始终使用长连接URL,以便您灵活地传递各种连接级别参数。 GitHub上的代码示例DataSourceSample有一个示例URL供参考。
JDBC:预言:瘦:@(DESCRIPTION =(ADDRESS =(HOST =为myhost)(PORT = 1521)(PROTOCOL = TCP))(CONNECT_DATA =(SERVICE_NAME = myorcldbservicename)))“;
答案 2 :(得分:0)
我遇到了这个问题。而且我错误地忽略了一行代码
driverManagerDataSource.setDriverClassName("oracle.jdbc.OracleDriver");
或在Bean配置中
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
我正在使用在Websphere上运行的Oracle 11G和Jersey + Boot服务器