任何人都可以指向教程,我可以在其中逐步看到从 Java 连接到 RDS。我已经下载了 SDK 并且能够连接到 S3。但是 SDK 没有任何连接到 RDS 的示例。而且在网络上也找不到任何有用的东西...
3 回答
明白了,它可以简单地连接到任何其他 jdbc。我遇到的问题是我的 IP 地址没有访问数据库的权限。我通过将 IP 地址放在 AWS 控制台中解决了这个问题
本 AWS 教程使用 RDS 存储应用程序数据,还向您展示了其他要求,例如设置入站规则。
我主要遵循本指南,忽略 .sql 文件、thymeleaf UI、"model.addAttribute("cities", city);" 部分,以及 html 文件: https ://zetcode.com/springboot/postgresql/
我的 application.properties 文件看起来像这样
postgres.comment.aa=https://zetcode.com/springboot/postgresql/
spring.main.banner-mode=off
logging.level.org.springframework=ERROR
spring.jpa.hibernate.ddl-auto=none
spring.datasource.initialization-mode=always
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://your-rds-url-here.us-east-1.rds.amazonaws.com:yourDbPortHere/postgres
spring.datasource.username=postgres
spring.datasource.password=<your db password here>
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
如果您有自定义架构,则可以将“?currentSchema=users”附加到 url:
spring.datasource.url=jdbc:postgresql://your-rds-url-here.us-east-1.rds.amazonaws.com:yourDbPortHere/postgres?currentSchema=users
感谢架构的这个 SO 答案: 是否可以在使用 JDBC 连接到 postgres 时指定架构?
这些其他几个链接也有帮助 https://turreta.com/2015/03/01/how-to-specify-a-default-schema-when-connecting-to-postgresql-using-jdbc/
https://doc.cuba-platform.com/manual-latest/db_schema_connection.html