B4J Library jSQL v1.20 - Asynchronous initialization

New method: SQL.InitializeAsync - Asynchronously initializes the SQL connection. This is useful when connecting to remote databases.

Usage example:
B4X:
#Region  Project Attributes
   #AdditionalJar: mysql-connector-java-5.1.27-bin
#End Region

Sub Process_Globals
   Dim sql1 As SQL
End Sub

Sub AppStart (Args() As String)
   sql1.InitializeAsync("sql1", "com.mysql.jdbc.Driver", _
     "jdbc:mysql://localhost/example?characterEncoding=utf8", "user", "password")
   StartMessageLoop 'only required in a console app
End Sub

Sub sql1_Ready (Success As Boolean)
   Log(Success)
   If Success = False Then
     Log(LastException)
     Return
   End If
   Dim rs As ResultSet = sql1.ExecQuery("SELECT table_name FROM information_schema.tables")
   Do While rs.NextRow
     Log(rs.GetString2(0))
   Loop
   rs.Close
End Sub

Make sure to copy the library to the internal libraries folder.
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Just in time for this nice Lib.
Thanks Erel.
 

jmon

Well-Known Member
Licensed User
Longtime User
Does Asynchronous means that the initialization and queries are on another thread? I always feel that the app freezes during the queries even in async mode.
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
i m using this example, but with the query on a button, when press execute the query.
this works fine(your example), but later 1 or 2 min, i try to press the button to execute the query again and this show

(EOFException) java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

Note(it on your example, only changed the query to a button)
 

Douglas Farias

Expert
Licensed User
Longtime User
already fixed, this error is not on b4j its on my host(server) the mysql close connections automatic later 60s
i made a timer on my jar, this make a query every 55s with select version() and the connection stay.

thx
 

prajinpraveen

Active Member
Licensed User
Longtime User
Please help.

I am in a process of developing an medium-complex application. I have to decide if this can be done using B4J or PHP. i have very limited knowledge of PHP.
1. is there anything that we cannot do with B4J which can be done by PHP alone (may be a very broad question)
2. is it safe to connect to mySQL from B4J using JSQL or should i always have a PHP script on the remote server to handle mySQL connections

thank you
 
Top