dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'mysql:mysql-connector-java:8.0.11' }
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;
public class DatabaseConnection { private static Connection connection;
static {
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/yourDatabaseNameHere";
String username = "yourDatabaseUsernameHere";
String password = "yourDatabasePasswordHere";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
return connection;
}
}
Connection connection = DatabaseConnection.getConnection();
connection.close();