ASyncTask doInBackground when getConnection
Posted by: Shaun van Wyngaard
Date: August 26, 2019 03:37AM

Hello. I am trying to get my Android Studio app to connect to my MySQL server.
I have placed the file mysql-connector-java-8.0.17.jar into …\users\…\app\libs\ folder (since I am developing on Windows I downloaded the "Platform Independent" version.

I have the following class

private class ConnectMySql extends AsyncTask<String, Void, String> {
String res = "";

@Override
protected void onPreExecute() {
super.onPreExecute();
}


@Override
protected String doInBackground(String... params) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://192.168.2.10:3306?";
url += "user=appuser&password=1234";
java.sql.Connection con = DriverManager.getConnection(url);
.
.
.
}

@Override
protected void onPostExecute(String result) {
txtData.setText(result);
}
}

However, as soon as it runs getConnection(url), it throws a runtime error

W/: Zip: Invalid filename
Zip: Invalid filename
Zip: Invalid filename
Zip: Invalid filename
Zip: Invalid filename
Zip: Invalid filename
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.mysqlapp, PID: 27515
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoSuchMethodError: No virtual method group(Ljava/lang/String;)Ljava/lang/String; in class Ljava/util/regex/Matcher; or its super classes (declaration of 'java.util.regex.Matcher' appears in /system/framework/core-libart.jar)
at com.mysql.cj.conf.ConnectionUrlParser.isConnectionStringSupported(ConnectionUrlParser.java:152)
at com.mysql.cj.conf.ConnectionUrl.acceptsUrl(ConnectionUrl.java:258)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:187)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:144)
at com.example.mysqlapp.MainActivity$ConnectMySql.doInBackground(MainActivity.java:72)
at com.example.mysqlapp.MainActivity$ConnectMySql.doInBackground(MainActivity.java:51)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 

Now I don't know if it is because it isn't seeing the .jar file as a zip file, or if it is the jdbc driver, or if it is some in the ASyncTask call.

Options: ReplyQuote


Subject
Written By
Posted
ASyncTask doInBackground when getConnection
August 26, 2019 03:37AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.