当我尝试使用 java / android 连接到 mysql 时出错
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
主要的:
//Conectar no Banco
conn = new ConnectMysql();
try {
conn.getConexato();
} catch (Exception e) {
Log.e("MYSQL", "Erro: " + e.getMessage());
}
}
连接Mysql:
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;
}