0

I have the same code written in Java and in Android to connect to a mysql-server. The same code in Java works, but in android it doesn't.

My Code:

 try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    try {
        String url1 = "jdbc:mysql://192.168.178.91:3306/db_meinungskanal?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
        String user = "user1";
        String password = "root";

        connection = DriverManager.getConnection(url1, user, password);
        if (connection != null) {
            System.out.println("Connected to the database");

        }
    } catch (SQLException ex) {
        System.out.println("An error occurred. Maybe user/password is invalid");
        ex.printStackTrace();
    }

In my android app I have granted acces to the internet with permissions, so I'm able to connect to internet. If I run the code in android it doesn't work and I get the following:

System.out: An error occurred. Maybe user/password is invalid 02-11 20:29:13.261 17036-17036/camelgmbh.com.meinungskanal W/System.err: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 02-11 20:29:13.261 17036-17036/camelgmbh.com.meinungskanal W/System.err: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Need help ;D

  • While not an answer to your question, please read: https://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android – Morrison Chang Feb 11 '18 at 20:58

1 Answers1

0

Android is not supporting MYSQL.You can utilize SQLite or Create web services to access MySQL data from the app.

Kirtan
  • 1,782
  • 1
  • 13
  • 35