The problem is I cannot connect to my MySQL database using Android Studio. I tried on Netbeans, and it works perfectly. It keeps on telling me that it could not create connection to database server, but the credentials are correct.
Versions I'm using:
Android Studio: 4.1.2
Android API: 16 4.1 (Jelly Bean)
MySQL Server: 8.0.18-google
Connector/J: 8.0.18
String host = "jdbc:mysql://XX.XXX.XXX.X:3306/xxx_database"; String user = "root"; String password = "XXXXXXXXXXXXXXXX";
Those above are correct, tested with Netbeans and c#.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = findViewById(R.id.text2);
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection(host, user, password); <= error here
txt.setText("Connected to database.");
} catch (SQLException | ClassNotFoundException throwables) {
txt.setText(throwables.getMessage());
}
}