Could you explain to me how I can connect to a database in android
studio, java
it is as easy as downloading a library and putting
public Connection getConexion(){
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/baseDeDatos","root","clave");
return con;
} catch (Exception e) {
//JOptionPane.showMessageDialog(null, "Error al conectarse con la BD: "+e.getMessage());
}
return con;
}
but I see that in android it is very different. Can you tell me step by step what I should do? I have already downloaded Xamp
. What library do I need? How is the class? In case of using a library, how do I place it in the project?
From what I see you need to connect your MySQL database with Android. But unfortunately this is not possible. Android does not support MySQL as the database engine to install it. The only solution you have is to make a web service that you must consume in your Android application and from this web service consult your MySQL database.
Another important point is that to do persistence (keep the values of your MySQL database in your Android application to manage, maintain, etc) you have to make an SQLite Database.
I leave you a complete Android SQLite Tutorial
The most recommended is to separate your logic in backend and frontend, as if it were a web application, for this I suggest an option and it is the consumption of Web services through the REST architecture style , I leave you this very complete tutorial where the step comes step by step how to consume and mount the web services.
It will seem a bit tedious at first but once you have everything configured, extending your requests will be quite easy.