Android Question Connect to Mysql Database


New Member
Licensed User
Hello, I try to connect to a Mysql Database i follow the tutorial here:, but i always have the same error:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
'#AdditionalJar: mysql-connector-java-8.0.26.jar
'#AdditionalJar:    mysql-connector-java-8.0.27.jar
#AdditionalJar: mysql-connector-java-5.1.34-bin
'#AdditionalJar: mysql-connector-java-5.1.22-bin
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Public mysql As JdbcSQL
    Private driver As String = "com.mysql.jdbc.Driver"
    Private jdbcUrl As String = "jdbc:mysql://"
    Private Username As String = "admin"
    Private Password As String = "xxxxxxx"
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private Button_OK As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)

    mysql.InitializeAsync("mysql", driver, jdbcUrl, Username, Password)

    Wait For MySQL_Ready (Success As Boolean)
    If Success = False Then
        Log("Check unfiltered logs for JDBC errors.")
    End If
    '    Return Success


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

I can connect to my database with my pc and the my sql workbench, so i thinks the loging from outside is ok
I add in the manifest
AddPermission("android.permission.ACCESS_NETWORK_S TATE")

If anybody can help me to connect


B4X founder
Staff member
Licensed User
Longtime User
Tip: switch to B4XPages. Your current code is wrong (not related to this error).

Try it with the v8 jdbc driver and change the driver class name to: com.mysql.cj.jdbc.Driver
Upvote 0


Licensed User
Longtime User
Try this
Upvote 0