Connect external MySQL in app to perform authentication [closed]

2

Hello, I need help making an app to access an environment control system. I need to perform the user authentication from an existing database, and, when performing this authentication (not needing to use a web service as it will be for local use only), it is necessary to show the user the ports he has access to , and then allow to open the app by clicking a button. Thank you.

    
asked by anonymous 23.05.2018 / 18:50

1 answer

2

You can perform database access the way you want, but this is not currently recommended as it is much more complex, impairs performance, and leaves your database vulnerable. It's not because your application does not run on the internet that you can not use a webservice to take responsibility for SQL queries.

If you still want to do this, just import the MySQL-to-Java connection library into your project and do the same as the database functions.

Connection example:

public void conectarMySQL(String host, String porta, String banco, String usuario, String senha){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch(Exception erro){
Log.e("MYSQL","Erro: "+erro);
}

    try{
        conn=DriverManager.getConnection("jdbc:mysql://"+host+":"+porta+"/"+banco+"?connectTimeout=9000&socketTimeout=9000&autoReconnect=true&secondsBeforeRetryMaster=3",usuario,senha);
        Log.i("MYSQL", "Conectado.");
    } catch(Exception erro){
        Log.e("MYSQL","Erro: "+erro);
    }
}

To use webservice you can even create your own queries. I use today, in an internal network only application (which seems to be your case) PHP + JSON, which made it much easier for me to work on the Android interface.

If you would like more references on the subject, here is a suggestion link: link

    
23.05.2018 / 21:49