![](/img/trans.png)
[英]MySql error “Cannot create PoolableConnectionFactory (Could not create connection to database server.)” while connecting with azkaban?
[英]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.