B4J Question jRDC issue with serialization

giggetto71

Active Member
Licensed User
Longtime User
Hi,
I have a MySQL server configured on the Rpi and a B4J non-ui app running JRDC server. the server runs ok and I can get ok connection from browser both locally and remote (from my PC).
the config is:
B4X:
#Lines starting with '#' are comments.
#Backslash character at the end of line means that the command continues in the next line.
#When making changes to the properties, rebuild the jRDC file.
#Host: Raspberry Pi
#Host IP: 192.168.1.123
#MySQL Version: 5.5.44
#Database: iotevents
#Table: iotevents


#MySQL DATABASE CONFIGURATION
DriverClass=com.mysql.jdbc.Driver
JdbcUrl=jdbc:mysql://localhost/iotevents?characterEncoding=utf8
User=user
Password=pw
#Java server port
ServerPort=17178

#SQL COMMANDS

sql.select=select * from iotevents
sql.select2=select sensor,type,event from iotevents
sql.insert=INSERT INTO iotevents(sensor,type,event) VALUES(?,?,?)
sql.update=UPDATE ioteventsSET sensor=?,type=?,event=? WHERE ID=?
sql.delete=DELETE FROM iotevents WHERE ID=?
sql.deleteall=DELETE FROM iotevents

On client side I followed the tutorial and I get:
B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
    #AdditionalJar: mysql-connector-java-5.1.37-bin
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Type DBResult (Tag As Object, Columns As Map, Rows As List)
    Type DBCommand (Name As String, Parameters() As Object)
    Private const rdcLink As String = "http://192.168.1.123:17178/rdc"
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    
    
    MainForm.Show
    GetRecords
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 Object) As DBCommand
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = Name
    If Parameters <> Null Then cmd.Parameters = Parameters
    Return cmd
End Sub

Sub GetRecords ()
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select2", Null)
    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

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

2 issues:

1- when I try the command "select 2" I just get nothing...apparently the code falls into the wait for job done but never ends. On server it says "commands: query:select 2: took 10ms, client 192.168.119 (my pc) so I assume the command makes it to the RPi but stuff don't get back.

2-when I try the command "select" (wjhich is a simple SELECT * from iotevents" I get the following error relevant (I think to the last field, the time stamp) see below the table structure.

CREATE TABLE iotevents (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,sensor VARCHAR(64),type VARCHAR(64), event VARCHAR(255),created TIMESTAMP DEFAULT NOW());


the error is:

Waiting for debugger to connect...
Program started.
ResponseError. Reason: java.lang.RuntimeException: Cannot serialize object: 2019-04-16 13:08:36.0, Response: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 java.lang.RuntimeException: Cannot serialize object: 2019-04-16 13:08:36.0</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /rdc. Reason:
<pre> java.lang.RuntimeException: Cannot serialize object: 2019-04-16 13:08:36.0</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>


Any idea?
thanks!!!
 
Top