B4J Question Error writing to MySQL database - This method does not support arrays of primitives.

Declan

Well-Known Member
Licensed User
Longtime User
I have the following code that receives HEX data from a GPS device via MQTT.
The code works great:
B4X:
            If (messageType = "3089") Then
                Dim myLat As String
                Dim myLon As String
                myLat = raw.SubString2(58,66)
                myLon = raw.SubString2(66,74)
            
                Dim b() As Byte=bc.HexToBytes(myLat)
                Dim Latitude() As Int=bc.IntsFromBytes(b)

                Dim b() As Byte=bc.HexToBytes(myLon)
                Dim Longitude() As Int=bc.IntsFromBytes(b)
                
                Log("Latitude: " & Latitude(0))
                Log("Longitude: " & Longitude(0))
                
                'sql.write_trans=INSERT INTO trans  VALUES (null,?,?,?,?,?,?,Now())
                Dim cmd As DBCommand = CreateCommand("write_trans", Array(deviceMAC,Latitude,Longitude, messageType,myfleet,myfriendname))
                Dim j As HttpJob = CreateRequest.ExecuteBatch(Array(cmd), Null)
                Wait For(j) JobDone(j As HttpJob)
                If j.Success Then
                    Log("write_trans OK")
                End If
                j.Release
                
            End If
But when I attempt to write to MySQL, I get the following error:
B4X:
Latitude: 282231833
Longitude: -256898516
java.lang.RuntimeException: java.lang.RuntimeException: This method does not support arrays of primitives.
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeList(B4XSerializator.java:269)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:221)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:224)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:79)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator$1.call(B4XSerializator.java:90)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator$1.call(B4XSerializator.java:1)
    at anywheresoftware.b4a.BA$4.run(BA.java:292)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.RuntimeException: This method does not support arrays of primitives.
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:233)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeList(B4XSerializator.java:269)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:237)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283)
    ... 15 more
Error building command: (RuntimeException) java.lang.RuntimeException: This method does not support arrays of primitives.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
This method does not support arrays of primitives.
you can't send thru the wire:
Dim Latitude() As Int

Create a list and add all the values to the list
B4X:
dim sendableLatitue as list
sendableLatitude.initialize
sendableLatitude.addAll(latitude)
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
But! as you are using JRDC2 for that, you wont be able to save a list into a column in MySQL, You may want to create a String with those values and store that string in the column, or create another table.
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
This works:
B4X:
Dim cmd As DBCommand = CreateCommand("write_trans", Array(deviceMAC,Latitude(0),Longitude(0), messageType,myfleet,myfriendname,date_string))
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…