繁体   English   中英

在连接到Amazon RDS时被阻止

[英]Blocked on connecting to Amazon RDS

我最近在Amazon RDS上部署了一个数据库实例,我正试图抓住它。 按照文档上的说明操作后,我尝试连接到该数据库实例,但出于某种原因,显示服务器版本的简单程序挂起在连接上。

这是我的代码:

import java.sql.*;

public class AWSTest {

    public static void main(String[] args) {
        System.out.println(getVersion());
    }

    public static String getVersion() {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            System.out.println("Driver Error: " + e.getMessage());
            return VERSION_NOT_FOUND;
        }

        System.out.println(CONNECTING_MESSAGE);
        try (Connection con = DriverManager.getConnection(DB_URL,
                USER,
                PASS);
                Statement stmt = con.createStatement();) {

            System.out.println("Getting server version...");
            try (ResultSet rs = stmt.executeQuery(VERSION_QUERY);) {
                rs.next();
                return rs.getString(1);
            }
        } catch (SQLException se) {
            System.out.println("SQL Error: " + se.getErrorCode() + " "
                    + se.getMessage());
            return VERSION_NOT_FOUND;
        }
    }


    static final String DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://**************.*******."
            + "*******.rds.amazonaws.com:3306";

    private static final String VERSION_QUERY = "Select VERSION()";
    static final String USER = "*******";
    static final String PASS = "*******";
    private static final String VERSION_NOT_FOUND = "Version was not found";

    public static final String GETTING_DRIVER_MESSAGE = "Getting driver...";
    public static final String CONNECTING_MESSAGE = "Connecting to server...";
}

我的程序挂起在Connection con = DriverManager.getConnection(DB_URL, USER, PASS); 而我的主要问题是它甚至没有抛出异常,只是停留在那里。

USERPASSDB_URL绝对是正确的。

这听起来像你的IP /端口被阻止/丢弃。 通常情况下连接什么都不做(而不是拒绝登录或登录失败)。 确保您的安全组已正确设置。 http://aws.amazon.com/rds/faqs/#31

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM