Android Question com.mysql.jdbc.exception.jdbc4.communications

ziz

Member
Hello you All ;
I am new to Android programming ;
With my first attempt, I encountered a torrent of problems ;
I saw some topics in the forum, but they did not help ;
What have I missed ;

the error Msg :

Untitled.jpg


Library Link Added :

B4X:
#AdditionalJar: mysql-connector-java-5.1.22-bin


Code For Connection .

B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim NAMA_VAR_HANDLER As MysqlHandler
    Dim NAMA_VAR_RESULT As ResultSet
End Sub


Sub conn
    
    ' NAMA_VAR_HANDLER.Initialize("nmServer","nmDatabase","nmUser","nmPassword")
    'NAMA_VAR_HANDLER.Initialize("localhost","test","root","root")
    NAMA_VAR_HANDLER.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql:/127.0.0.1:3306/test","ali","JToX0lCmdHslAL1Q")
    If NAMA_VAR_HANDLER.isConnected = False Then
        Msgbox(NAMA_VAR_HANDLER.SQLError, "Error")
        
        Return
    End If
End Sub

The problem may be minor
It may have been addressed in the forum
Unfortunately, I did not find a cure
And Thank you who will waste some time to help
 

ziz

Member
I recommend you to use JdbcSQL.

Isn't this the same library that I used Erel ...?

B4X:
NAMA_VAR_HANDLER.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql:/127.0.0.1:3306/test","ali","JToX0lCmdHslAL1Q")


com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.

And I test Connection Parameters in vs code & I have No Problem ;

aaa.jpg
 
Last edited:
Upvote 0

ziz

Member
By The Way I Use Your Example Here :

JdbcSQL - Directly connect to remote databases

I got a black screen and a message saying : Completed. Success: False
And when I click on the screen the [ProgressBar] appears Done disappears

in Log Window I Saw Warning tell me change manifest file to android 29 & it's Recommended
When I Do that I have this Msg :

** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Check unfiltered logs for JDBC errors.
Completed. Success: false

I got a black screen and a message saying : Completed. Success: False
And when I click on the screen the [ProgressBar] appears Done disappears
and nothing in log window
 
Upvote 0

ziz

Member
Let me try Other way
After using the JdbcSQL and it didn't work, I thought about seeing the permissions
I added the following two lines in Manifest File:

  1. AddPermission("android.permission.INTERNET")
  2. AddPermission("android.permission.ACCESS_NETWORK_S TATE")

XML:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>

AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_NETWORK_S TATE")

)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

And a mistake occurred and got [ AndroidManifest.xml:12: error: Error parsing XML: not well-formed (invalid token) ]
so I try ohter way :

XML:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
<uses-permission android:name="ANDROID.PERMISSION.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_S TATE" />
)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

And a mistake occurred and got [ AndroidManifest.xml:12: error: Error parsing XML: not well-formed (invalid token) ]
so I try ohter way :
I removed the two lines

XML:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

but the problem remained ;
Error Msg when Compile:

B4A Version: 10.50
Parsing code. (0.00s)
Java Version: 11
Building folders structure. (0.04s)
Compiling code. (0.01s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. (0.00s)
Compiling debugger engine code. (0.00s)
Compiling generated Java code. (0.00s)
Convert byte code - optimized dex. (1.42s)
Packaging files. Error
AndroidManifest.xml:12: error: Error parsing XML: not well-formed (invalid token)

AAPT path: D:\AndroidStudio\Sdk\tools\..\build-tools\30.0.2\aapt.exe
Exit code:1
 
Last edited:
Upvote 0

ziz

Member
Well I resolved the related issue permission & Manifest File
but the connection issue is still there

XML:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_NETWORK_STATE")   
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
 
Upvote 0

ziz

Member
there is nothing appear in log window so i add one line to the sub named [ ResumableSub ]
I try catch any Error by LastException

B4X:
If Success =False  Then
Sub Connect As ResumableSub
     mysql.InitializeAsync("mysql", driver, jdbcUrl, Username, Password)
    'mysql.Initialize2("mysql", jdbcUrl, Username, Password)
    Wait For MySQL_Ready (Success As Boolean)
    If Success =False  Then
        Log("Check unfiltered logs for JDBC errors.")
        Log(LastException)
    End If
    Return  Success
End Sub
End If

then I Get :

Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Check unfiltered logs for JDBC errors.
(ErrnoException) android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
Completed. Success: false

i don't know way & what happened
port 3306 work will in windows firewall
connection parameters work will in other programs

i delete xampp and use this version
https://cdn.mysql.com//Downloads/MySQLInstaller/mysql-installer-community-8.0.23.0.msi

The connection did not work either
 
Last edited:
Upvote 0
Top