B4J Question ConnectionPool Connected Event?

jmon

Well-Known Member
Licensed User
Longtime User
Hello,

Is there a way to know if the connection pool is connected? SQL has a "_Ready (Success As Boolean)" event when SQL is connected, but it seems that ConnectionPool doesn't have one.

B4X:
Sub Connect
    Pool.Initialize("com.mysql.jdbc.Driver", _
                $"jdbc:mysql://${MySQLHost}:${MySQLPort}/${MySQLDB}?characterEncoding=utf8"$, MySQLUSR, MySQLPW)
End Sub

How can I know if I'm connected? Do I need to request a connection right after Initialize?
B4X:
Sub Connect
    Pool.Initialize("com.mysql.jdbc.Driver", _
                $"jdbc:mysql://${MySQLHost}:${MySQLPort}/${MySQLDB}?characterEncoding=utf8"$, MySQLUSR, MySQLPW)
    Pool.GetConnectionAsync("IsConnected")
End Sub

Private Sub IsConnected_ConnectionReady (Success As Boolean, SQL As SQL)
    If Success Then
        log("Connected")
    Else
        Log("Not Connected")
    End If
    SQL.Close
End Sub


Thank you for your help.
 

keirS

Well-Known Member
Licensed User
Longtime User
As I understand it you will not get a connection until the connection is connected. Erel has configured the c3po instance so that testConnectionOnCheckout is true . This means that the connection is tested with a query (default is Select 1) to ensure the connection is working before being issued from the pool. If it isn't working it wont be issued.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Yes this is what I understood too. I just didn't wanted to ask for a connection if I wasn't connected.

for my UI, I wanted to get a visual feedback on the connection status. I guess the only way to know if I'm disconnected, is to fail at getting one. To know if I'm connected, I should have no errors at getting a connection.

Thanks for your answer.
 
Upvote 0
Top