2013-10-28 80 views
0
當我嘗試用java連接到MySQL

是給錯誤/安卓無法連接到MySQL在JAVA

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. 

錯誤: 無法創建連接到數據庫服務器。

10-28 18:25:05.621: D/AbsListView(20635): Get MotionRecognitionManager 
10-28 18:25:05.626: E/MYSQL(20635): Erro: Could not create connection to database server. 
10-28 18:25:05.626: E/MYSQL(20635): Erro: java.lang.NullPointerException 
10-28 18:25:05.626: W/System.err(20635): Got an exception! 
10-28 18:25:05.626: W/System.err(20635): Could not create connection to database server. 
10-28 18:25:05.636: E/MYSQL(20635): Erro: java.lang.NullPointerException 

MAIN:

//Conectar no Banco 
    conn = new ConnectMysql(); 
    try { 
     conn.getConexato(); 

    } catch (Exception e) { 
      Log.e("MYSQL", "Erro: " + e.getMessage()); 
    } 

} 

ConnectMysql:

public Connection getConexato() throws ClassNotFoundException, 
    SQLException, java.sql.SQLException, InstantiationException, 
    IllegalAccessException { 

    Class.forName("com.mysql.jdbc.Driver").newInstance(); 

    conn = (Connection)  DriverManager.getConnection("jdbc:mysql://mysql.hostinger.com.br:3306/u917553846_123","u917553846_admin","teste123"); 

    return conn; 
} 
+0

將堆棧跟蹤添加到您的錯誤日誌中:'Log.e(e);'這會給你更多關於拋出'NullPointerException'的信息 – Niro

+0

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:可能不創建與數據庫服務器的連接。 – user2774657

回答

0

請檢查Android應用程序有訪問互聯網上的服務正確的權限。

<manifest xlmns:android...> 
... 
<uses-permission android:name="android.permission.INTERNET"></uses-permission> 
</manifest> 
+0

是的,有權限INTERNET – user2774657

+0

好的,你能解決主機名,例如通過'nslookup'? –

+1

nslookuo?不知道 – user2774657

0

mysql.hostinger.com.br是不存在的域。你確定你的分貝地址嗎?