【发布时间】:2020-01-12 06:35:30
【问题描述】:
我知道如何以通常的方式连接到数据库。我需要的是在运行时选择要连接的数据库。
我有一个默认数据库(由系统使用)和许多其他选项供用户选择获取数据。这意味着没有任何实体或 JPA 映射。
以前我用这个:
try (Connection connection = DriverManager.getConnection(connectionString, user, password);
PreparedStatement preparedStatement = connection.prepareStatement(nativeQuery)) {
preparedStatement.setString( 1, coordinate );
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next())
result = resultSet.getString(RESULT_PARAM);
}
} catch (SQLException ex) {
CodeUtils.log(QUERY_ERROR_MSG, this);
CodeUtils.log(ex.getMessage(), this);
}
但我不知道如何将它移植到 Spring Boot。
【问题讨论】:
-
没关系。我发现了这个:stackoverflow.com/questions/52845453/…。对不起。
标签: spring postgresql spring-boot jpa