Best option is to let ConnectionPool take care of it
I just tried this, and have a question in regards to it.
Using the following code it connects to the MySQL database:
Dim sql1 As SQL
sql1.InitializeAsync("sql1", "com.mysql.jdbc.Driver","jdbc:mysql://IP_address_here/database?characterEncoding=utf8","username","password")
wait for sql1_ConnectionReady (Success As Boolean)
If Success = False Then
Log(LastException)
Else
Log("ready = OK")
End If
The above code works without the connectionPool.
I then used the code below to connect with the ConnectionPool like:
(Hopefully I have done this correct)
Dim sql1 As SQL
Dim pool As ConnectionPool
pool.Initialize("com.mysql.jdbc.Driver","jdbc:mysql://IP_address_here/database?characterEncoding=utf8","username","password")
sql1 = pool.GetConnection
pool.GetConnectionAsync("IsConnected")
Private Sub IsConnected_ConnectionReady (Success As Boolean, SQL As SQL)
Log("SQL Connect = " & Success)
End Sub
This allows me to connect to the MySQL database using the ConnectionPool.
Few questions to ask:
1. When the B4J app loses connection to the MySQL, does the ConnectionReady event get triggered or do I need to run the code:
pool.GetConnectionAsync("IsConnected")
and then check the ConnectionReady event for the status? I am guessing I would need to use a Timer and run this code every minute to check the status.
2. Does the ConnectionPool (Pool) lose connection to the database, or is it the SQL (sql1) the one that loses connection when connecting to the remote database? I am guessing it's the pool that loses connection.