如何使用 Java 从 AWS RDS 实例访问数据
How to access data from an AWS RDS instance using Java
我在 AWS 中创建了这个数据库
database-1.ccbrzww0e8op.eu-west-1.rds.amazonaws.com
我正在尝试使用此 URL、
进行连接
jdbc:mysql://database-1.ccbrzww0e8op.eu-west-1.rds.amazonaws.com:3306/database-1
但是我有这个错误:
[08S01]
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
我假设您正在编写自己的 Java 连接 Class。要确保 Spring 应用程序可以与 Amazon RDS 实例通信,您需要:
确保您的应用程序具有数据库驱动程序文件。这可以通过使用 POM 文件来完成。
确保您的 RDS 实例配置为允许 public 访问。
确保您已设置入站规则以允许您的开发计算机访问数据库。有关设置安全组入站规则的信息,请参阅 Controlling Access with Security Groups。
执行这些任务后,您的 Spring BOOT 应用程序可以连接到数据库并查询数据,如这张 Spring BOOT 应用程序从 RDS 实例查询数据的图片所示:
我在 AWS 中创建了这个数据库 database-1.ccbrzww0e8op.eu-west-1.rds.amazonaws.com
我正在尝试使用此 URL、
进行连接jdbc:mysql://database-1.ccbrzww0e8op.eu-west-1.rds.amazonaws.com:3306/database-1
但是我有这个错误:
[08S01]
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
我假设您正在编写自己的 Java 连接 Class。要确保 Spring 应用程序可以与 Amazon RDS 实例通信,您需要:
确保您的应用程序具有数据库驱动程序文件。这可以通过使用 POM 文件来完成。
确保您的 RDS 实例配置为允许 public 访问。
确保您已设置入站规则以允许您的开发计算机访问数据库。有关设置安全组入站规则的信息,请参阅 Controlling Access with Security Groups。
执行这些任务后,您的 Spring BOOT 应用程序可以连接到数据库并查询数据,如这张 Spring BOOT 应用程序从 RDS 实例查询数据的图片所示: