Android Question B4A - Jdbc Firebirdsql - Problem Connection

Helcione Madalena

New Member
Licensed User
Longtime User
Hello people,

I am trying to communicate with the Firebird bank, using JDBC, as it is simpler and more straightforward, without having to install another tool on the client's machine, but I am not succeeding.

He just stands there, waiting for an answer on the line:

Wait For MySQL_Ready (Success As Boolean)

Follow the code I'm using, can someone help me?


B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    Public mysql As JdbcSQL   
    Private driver As String = "org.firebirdsql.jdbc.FBDriver"
    Private jdbcUrl As String = "jdbc:firebirdsql://10.0.1.4:3050/C:/Users/admin/Desktop/JdbcSQL/db/TESTE_OFC.FDB"
    Private Username As String = "sysdba"
    Private Password As String = "masterkey"
End Sub

Sub Service_Create
    'need to disable it as reading from large JdbcResultSet will cause network requests to be sent on the main thread.
    DisableStrictMode
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

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

Sub Connect As ResumableSub
    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 CloseConnection
     mysql.Close
End Sub

Sub select_teste_firebird As ResumableSub
    Wait For (Connect) Complete (Success As Boolean)
    If Success Then
        Try
            Dim sf As Object = mysql.ExecQueryAsync("mysql", "SELECT * FROM clientes ", Null)
            Wait For (sf) mysql_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
            If Success Then
                Do While Crsr.NextRow
                    Log($"Id: ${Crsr.GetInt("id")}, Name: ${Crsr.GetString("nome")}"$)
                Loop
                Crsr.Close
            End If
        Catch
            Success = False
            Log(LastException)
        End Try
        CloseConnection
    End If
    Return Success
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Private jdbcUrl As String = "jdbc:firebirdsql://10.0.1.4:3050/C:/Users/admin/Desktop/JdbcSQL/db/TESTE_OFC.FDB"
I´m not sure this url would work to connect from android to your DB Machine. The IP is NOT a ip you can reach when you are not in the same network.

i would start with a url like

B4X:
Private jdbcUrl As String = "jdbc://publicip:3050/C:/Users/admin/Desktop/JdbcSQL/db/TESTE_OFC.FDB"
'or
Private jdbcUrl As String = "jdbc://10.0.1.4:3050/C:/Users/admin/Desktop/JdbcSQL/db/TESTE_OFC.FDB" ' if you are in the same network
 
Upvote 0

Helcione Madalena

New Member
Licensed User
Longtime User
The connection is local, so the internal ip.
And I tested the string, as you said it doesn't work, and I can't even see the error, it only appears for Check unfiltered logs for JDBC errors.

But nothing appears in the logs !!
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Did you use this JDBC Driver:

?
 
Upvote 0

Albert Kallal

Active Member
Licensed User
I would fire up the firebase "manager" on another computer on that network. Can it connect?
You could for a quick test also turn off firewall settings if that Firebird database server is not some actual server that other types of clients can connect to.

So I would test/get/try/ensure that you can connect to that database from other computers. If that works, then you can go back to playing with the android connection.
 
Upvote 0
Top