Sorry for the probably naive question but, coming from .net framework, I've always used several objects / constructs to interact with the db, which I am struggling to reproduce on B4J.
I am missing mainly the DataTable object concept, which in .net allows me to get a "table" subset, matching an sql query:
As far as I can see, on B4J I can only get a reader cursor as a resultset as the only way to interact with data. Is this correct ?
Also, if I create a sub which returns a ResultSet, the ResultSet is held on memory ? (Is it ok to close the sql connection I fetched earlier from the pool, in order to grab the ResultSet ?
I.E. is this correct ?
I am missing mainly the DataTable object concept, which in .net allows me to get a "table" subset, matching an sql query:
B4X:
Public Shared Function getdatatable(ByVal query As String) As DataTable
Dim adapter As mysqlDataAdapter = db.adaptador(query)
Dim tabla As New DataTable
adapter.Fill(tabla)
getdatatable = tabla
adapter.Dispose()
End Function
As far as I can see, on B4J I can only get a reader cursor as a resultset as the only way to interact with data. Is this correct ?
Also, if I create a sub which returns a ResultSet, the ResultSet is held on memory ? (Is it ok to close the sql connection I fetched earlier from the pool, in order to grab the ResultSet ?
I.E. is this correct ?
B4X:
Sub Class_Globals
Public pool As ConnectionPool, mysql As SQL
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
Try
pool.Initialize("com.mysql.cj.jdbc.Driver", "jdbc:mysql://localhost/test?characterEncoding=utf8", _
"xxxx", "yyyy")
Log("MySQL pool started")
pool.GetConnection.Close
Catch
Log("MySQL pool error")
ExitApplication
End Try
End Sub
Sub read(query As String) As ResultSet
mysql = pool.GetConnection
Dim RS As ResultSet
Try
RS = mysql.ExecQuery(query)
Catch
Log(LastException)
End Try
mysql.close
Return RS
End Sub