Android Question jdbcSQL - Unable to connect to MySQL Server ver 8.0.30

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

As said in the title, I am using jdbcSQL to connect to a MySQL server ver 8.0.30

I understand that the app is not connecting to the server. The problem appeared after upgrading and moving to a new MySQL server ver 8.0.30 on a different server. Earlier this was working fine.

Please note that I am able to connect to this same database from my other desktop application using the same username and password without any change. It is a remote Database. It is failing ONLY in B4A.

On the Logs, it is written "Check unfiltered logs for JDBC errors". When I checked the unfiltered logs I found the following error message

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server

Somewhere in this forum, I read that a few of our members faced similar issues and that the problem is only in release mode and that it works fine in debug mode. Erel has already provided a solution for Disabling Strict mode. I have also used the code to disable Strict Mode using the already available code on this forum. For me, it is not working in debug mode and release mode.

B4X:
Sub DisableStrictMode
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Build.VERSION")
    If jo.GetField("SDK_INT") > 9 Then
        Dim policy As JavaObject
        policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
        policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
        Dim sm As JavaObject
        sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
    End If
End Sub

I am already aware that jRDC2 is the best way, but for now, I have to make this app up and running as early as possible. Hence any hint to resolve this issue would be appreciated

I am using B4A version 11.50

The same problem is there in another B4A app of mine, which is connecting to a different database, but residing on the same server. This app does not use jdbcSQl instead it uses the library from DonManfred. I know it is not recommended to use this library anymore. It is an app written in the year 2017 and all these years it worked fine until I moved to a different server and upgraded the MySQL version to 8.0.3

I am not sure whether it is impossible to connect to MySQL ver 8.0.3 directly from Android phones nowadays

Regards
Anser
 
Last edited:

Anser

Well-Known Member
Licensed User
Longtime User
I changed the following AdditionalJar statement from
B4X:
#AdditionalJar: mysql-connector-java-5.1.34-bin
To
B4X:
#AdditionalJar: mysql-connector-java-8.0.28
I also changed the Driver from
B4X:
"com.mysql.jdbc.Driver"
To
B4X:
"com.mysql.cj.jdbc.Driver"

The jdbcurl used is
Dim jdbcUrl As String = "jdbc:mysql://MyIpAddress:3306/MyDatabaseName"

With the above said changes, now, in the unfiltered log it is not showing any error, but the application goes into some infinite loop mode and waits indefinitely while trying to connect to the database.
B4X:
Sub Connect As ResumableSub
    Log("-----inside connect")
    mysql.InitializeAsync("mysql", DbService.driver, DbService.jdbcUrl, DbService.cDbUserName, DbService.cDbPassword)
    Wait For MySQL_Ready (Success As Boolean)
    If Success = False Then
        Log("Check unfiltered logs for JDBC errors.")
    End If
    Return Success
End Sub
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Is there any other way to get it running. ?
Or is it that this combination cannot work on Android and that I have to uninstall MySQL ver 8.0.30 and then install the old version MySQL 5.7 ?
Of course, I do understand that jRDC2 is the way to go.
 
Upvote 0

calloatti

Member
Licensed User
I am using jdbcsql with a mysql 5.1.43 server in an B4A app with no problems. I already have a running mysql 8.0.25 in my dev machine, so I did some tests. I tested connecting my B4A app to that server without changing anything. This is what I had to do to make it work:

See https://stackoverflow.com/questions...n-type-from-standard-to-caching-sha2-password

I used this:

SQL:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD  EXPIRE NEVER; ALTER USER 'root'@'localhost' IDENTIFIED WITH  mysql_native_password BY '{NewPassword}';

And everything works fine, without having to change anything in the B4A app except the mysql server port (just because I have mysql 5 on port 3306 and mysql 8 on port 3308)

Adjust the SQL command to the required username and password. You will probably want to remove the "@'localhost'" part to connect from other hosts.

Of course this means you are using legacy authentication, but I am sure you understand all that.
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
I am using jdbcsql with a mysql 5.1.43 server in an B4A app with no problems. I already have a running mysql 8.0.25 in my dev machine, so I did some tests. I tested connecting my B4A app to that server without changing anything. This is what I had to do to make it work:

See https://stackoverflow.com/questions...n-type-from-standard-to-caching-sha2-password

I used this:

SQL:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD  EXPIRE NEVER; ALTER USER 'root'@'localhost' IDENTIFIED WITH  mysql_native_password BY '{NewPassword}';

And everything works fine, without having to change anything in the B4A app except the mysql server port (just because I have mysql 5 on port 3306 and mysql 8 on port 3308)

Adjust the SQL command to the required username and password. You will probably want to remove the "@'localhost'" part to connect from other hosts.

Of course this means you are using legacy authentication, but I am sure you understand all that.
I have already applied the "mysql_native_password" option for the database user. Unfortunately, can't figure out what is happening. In my case, I am connecting to a remote database. My other desktop applications are able to connect without any changes in the code (except the change in the IP of the database)
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
This could be the solution 👇


Haven't tried the above solution, as I was in a hurry to somehow make my app up and running I uninstalled MySql server ver 8 and went back to MySQL server ver 5. I am sure that this solution would work.
 
Upvote 0
Top