0

Android version of DriverManager import section looks like this

//  Android\SDK\sources\android-27\java\sql\DriverManager.java
package java.sql;

import java.util.Iterator;
import java.util.ServiceLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.CopyOnWriteArrayList;

import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;

An exception is raised when I call getConnection(), and hence I could not access the database. It says - (Cannot resolve symbol CallerSensitive) and (Cannot resolve symbol Reflection).

Java SE version Drivermanager import looks like this

package java.sql;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Stream;

import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;

This worked fine when I wanted to connect to mysql using jdbc.

api-27,28,29,30 all have same imports. Can anyone help me how to connect to mysql using JDBC?

  • I understand that we can connect through a server(say PHP backend), but my aim is to connect the java application directly to a remote MySql. @LukeWoodward, can you help me in this context? The problem I'm facing might be a version mismatch, but I'm unable to figure it out. – Khagesh vgs Dec 08 '20 at 20:54
  • @LukeWoodward are you saying that it is not possible to connect using JDBC? – Khagesh vgs Dec 08 '20 at 20:58
  • I'm not saying it's impossible. Other Stack Overflow questions show you how to, if you really want to. I'm saying it's strongly discouraged. For one thing, suppose your app gets compromised. An attacker can decompile it and get credentials for your database, which they can then use to to wipe it, fill it with offensive or abusive content, etc. Also, JDBC doesn't work well over unreliable network connections such as cellular networks. Android does have some JDBC functionality, but that seems to be for the benefit of SQLite and other such databases where the database is on the device. – Luke Woodward Dec 09 '20 at 21:31
  • In addition, recent MySQL Connector/J versions don't work on Android, because they use features (like named regex groups) that are not available on Android. – Mark Rotteveel Dec 10 '20 at 13:18

0 Answers0