Connect external Mysql in app to perform authentication

Asked

Viewed 457 times

2

Hello, I need help making an app for access to an environment control system. I need to authenticate the user, 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 you to open it by the app by clicking a button. Thank you.

  • 2

    and what your brother doubt?

  • 1

    I made an answer to your question, but here you should put the problem you are having when making your code and not ask for a code ready.

1 answer

1

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

If you still want to do this, simply import the Mysql connection library into Java in your project and perform the same functions of the database.

Example of connection:

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 the webservice you can do yours yourself, creating the queries you want. I use today, in an internal network only application (which seems to be your case) PHP + JSON, which greatly facilitated my work on the Android interface.

If you want more references on the subject, there is a suggestion link: https://www.androidpro.com.br/blog/armazenamento-de-dados/usando-banco-de-dados-externo-no-android/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.