Android Question Get Query Result as String MySql jRDC2 Help!

Hi! its me again... the thing is, I want to have my query result as string and assign it to a variable.

B4X:
Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("validate", Array(uName.text,pWord.text))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'work with result
        req.PrintTable(res)

My Sql query is this
sql.validate=SELECT `UserID` FROM `tbl_userinfo` WHERE `Username` = ? AND `Password`= ?

so basically, I wanted to take the data from UserID from the results of the query, i've been stuck in here, I tried j.getstring, etc.. but I don't really know what to do.
 

josejad

Expert
Licensed User
Longtime User
Take a look to the PrintTable sub in DBRequestManager to get some ideas.
As you can see, what you get is a DBResult object
B4X:
Type DBResult (Tag As Object, Columns As Map, Rows As List)

'Prints the table to the logs.
Public Sub PrintTable(Table As DBResult)
'    Log("Tag: " & Table.Tag & ", Columns: " & Table.Columns.Size & ", Rows: " & Table.Rows.Size)
    Dim sb As StringBuilder
    sb.Initialize
    For Each col In Table.Columns.Keys
        sb.Append(col).Append(TAB)
    Next
'    Log(sb.ToString)
    For Each row() As Object In Table.Rows
        Dim sb As StringBuilder
        sb.Initialize
        For Each record As Object In row
            sb.Append(record).Append(TAB)
        Next
        Log(sb.ToString)
    Next
End Sub

So, make some tries in your code with the piece of code from lines 12 to 19 from PrintTable Sub
B4X:
Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("validate", Array(uName.text,pWord.text))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'work with result
        req.PrintTable(res)
    For Each row() As Object In res.Rows 'Remember, res is a DBResult, (Tag As Object, Columns As Map, Rows As List)
        For Each record As Object In row
            log(record) 'Probably here you will have your UserID
        Next
    Next
 
Upvote 0
Top