Android Question SQL paramater query

Spuds

Member
Licensed User
I have a JRDC server running attached to a MySQL db using java 8.0.19 connector.
Attempting to pass a query with a single parameter and I am getting below error.

Thank you for any assistance.

Error compiling program.
Error description: Cannot cast type: {Type=String,Rank=1, RemoteObject=True} to: {Type=Long,Rank=1, RemoteObject=True}
Error occurred on line: 83
If Parameters <> Null Then cmd.Parameters = Parameters
Word: parameters

B4A:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Type DBResult (Tag As Object, Columns As Map, Rows As List)
    Type DBCommand (Name As String, Parameters() As Long)
    Private const rdcLink As String = "http://192.168.0.200:17178/rdc"

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Image_USOPENlogo As ImageView
    Private Bgndpanel As Panel
    Private lookupkey As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("2")
     Get_badge
    Bgndpanel.Color=Colors.Red


End Sub
Sub Get_badge
    Dim req As DBRequestManager = CreateRequest
    'Dim CMD As DBCommand= CreateCommand("get_badge,"178")
    lookupkey=178
    Dim CMD As DBCommand=CreateCommand("get_badge",lookupkey)

    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)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub
Sub SpnrCountry_ItemClick (Position As Int, Value As Object)
   
End Sub

Sub SpnrCity_ItemClick (Position As Int, Value As Object)
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub CreateRequest As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Me, rdcLink)
    Return req
End Sub

Sub CreateCommand(Name As String, Parameters() As String) As DBCommand
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = Name
    If Parameters <> Null Then cmd.Parameters = Parameters
    Return cmd
End Sub
 

Albert Kallal

Active Member
Licensed User
A quick wild guess?
Your lookupkey is a string - and it wants a int or long number.
As a test, try: "select gte_badge from tblWhatever where ID = " & lookupkey
In this case, then lookey can be a string - it will not matter since you formed the sql string correct. However for numbes (no quotes), and for strings then the parmeter behind the scenes is automatic "quoted" for you. And the same goes for dates. So, you want the library code to do this dirty work.

if the lookup key value is a long/int value on the server side - then define that as a long in your code. The error message does give a hint here.

And this gets rather messay if a string is null. I call this the Java Schrödinger's cat issue! To look inside that null box, but as a string, then the word "null" is retuned.

So, if you were say to search for a null vallue in a column, you wold use:
Dim MySearchParm as Object
'bla bla code, and then:
MySearchParm = Null

If MySearchParm is a string, then null value will in fact get converted to the word "Null" and you search for a string called "Null".

So letting the routines do "type" conversion for you is rather nice - but you do have to match up the data types when doing this.

Edit:
And your parameters have to be typed to the correct type - not strings.
So, use a "list"
eg:
B4X:
    Dim v As List
    v.Initialize2(Array As Object("Jasper","Albert","Kallal",123))

Edit:
Note how in above, the first 3 are strings, but the last value is NOT a string. The parameters are "different" types - they can't all be strings.
So, you can't use an array() of strings here. But a list of "different" types such has strings or integers should work.


Regards,
Albert D. Kallal
Edmonton, Alberta Canada[/code]
 
Last edited:
Upvote 0
Top