当我尝试使用 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());
}
}
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;
}
最佳答案
请检查 Android 应用是否具有访问互联网服务的正确权限。
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
关于java - JAVA无法连接Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19644531/