【发布时间】:2019-05-24 10:24:30
【问题描述】:
我使用 H2 数据库进行测试,但我使用 Oracle 进行生产。我正在尝试使用以下查询。
SELECT ROWNUM as id, name, state FROM info;
以下配置
public class DatabaseConfiguration {
private final static DriverManagerDataSource dataSource = initializeDataSource();
@Bean
@Profile("test")
public DataSource dataSource() {
return dataSource;
}
private static DriverManagerDataSource initializeDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.h2.Driver");
dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;MODE=Oracle;");
dataSource.setUsername("sa");
dataSource.setPassword("sa");
return dataSource;
}
}
但我收到了java.util.NoSuchElementException。 H2 是否支持 ROWNUM?
【问题讨论】:
-
您没有指定您打算如何使用行号,但由于 Oracle 中最常见的用法是分页查询,因此请注意 H2 为此目的支持
LIMIT和OFFSET.请参阅文档中的SELECT和 Result Sets。
标签: oracle spring-boot spring-data-jpa h2