You need to connect to the external MySQL database in the Android application, which would use the resources of the finished service, but without the API. I know that this is not good, but this task is just worth it.
How can I do that?
You need to connect to the external MySQL database in the Android application, which would use the resources of the finished service, but without the API. I know that this is not good, but this task is just worth it.
How can I do that?
In order to connect to the database you will need:
1. Connect to the project JDBC Driver
for MySQL
. If you are using AS
then add the following line in the dependencies:
compile 'mysql:mysql-connector-java:5.1.6'
2. Before the first access to the database, you must register the driver:
try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println("Where is your MySQL JDBC Driver?"); e.printStackTrace(); return; }
The com.mysql.jdbc.Driver
string depends on the connected driver.
3. Get the connection to the base as follows:
Connection conn = DriverManager.getConnection("jdbc:mysql://hostname:port/dbname","username", "password");
Naturally replace the hostname, port, dbname, username and password with your own.
PS : and yes, we do not forget to make the connection and all kinds of manipulations with the base not in the UI stream . You should not forget about permissions in the manifesto.
Source: https://ru.stackoverflow.com/questions/507324/
All Articles