繁体   English   中英

SQLException: 无法创建到数据库服务器的连接。 SQLState: 08001

[英]SQLException: Could not create connection to database server. SQLState: 08001

我正在尝试使用 JDBC 将我的 android studio 连接到我的 AWS rds。

public void GetText(){
    TextView tx1 = findViewById(R.id.login_title);
    ConnectionURL = "jdbc:mysql://awsrds-endpoint:3306/supplychain?user=admin&password=admin123";

    try {
        System.out.println("Loading driver...");
        Class.forName("com.mysql.cj.jdbc.Driver");
        System.out.println("Driver loaded!");
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Cannot find the driver in the classpath!", e);
    }

    Connection conn = null;
    Statement setupStatement = null;
    Statement readStatement = null;
    ResultSet resultSet = null;
    String results = "";
    int numresults = 0;
    String statement = null;

    try {
        System.out.println("Connecting ...");
        conn = DriverManager.getConnection(ConnectionURL);
        System.out.println("Connected");
        readStatement = conn.createStatement();
        resultSet = readStatement.executeQuery("SELECT S_ID FROM STAFF;");
        conn.close();

    } catch (SQLException ex) {
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    }
}

和我的错误:

I/System.out: SQLException: 无法创建到数据库服务器的连接。 SQLState: 08001 供应商错误: 0

这里的问题无关紧要 - 不要像这样连接到数据库。 为了做到这一点,您需要将您的用户名和密码以明文形式存在于您的应用中。 反编译应用程序并获取它是微不足道的。 这是不安全的。 您应该只通过网络服务访问远程数据库。 这样您的用户名和密码就不需要离开您自己的设备。

暂无
暂无

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

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