Android Question Using Wait for in JRDC

incendio

Well-Known Member
Licensed User
Longtime User
Hello all,

I have these codes
B4X:
Sub Test
   If(reqM.IsInitialized = False) Then reqM.Initialize(Me, Main.PUB_CONN_STR)
   Private cmd As DBCommand
   cmd.Initialize
 
   cmd.Name = "send_bnk1"
   cmd.Parameters = Array As Object(1,2,3)
         
   Wait For (reqM.ExecuteCommand(cmd,"send_bnk1")) JobDone(j As HttpJob)
   If j.Success Then
        Log(1)
        Msgbox("OK","")
   Else
        Log(0)
        Msgbox("ERR","")
   End If
End Sub

Sub JobDone(Job As HttpJob)
   If Job.Success = False Then
       If Job.Tag = "send_bnk1" Then
           Rsl = -1
       End If
   Else
       If Job.Tag = "send_bnk1" Then
           Rsl = 1
       End If
   End If
   Job.Release
End Sub

Sub Test runs without error but there is no log or message box appear, why is that?
Am I missing something here? (Using B4A 8)

Note : the java Server was not running, so the value of j.Success should be false.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip: Never use modal dialogs. Use MsgboxAsync instead.

There are several mistakes in your code. I recommend you to watch the video tutorial: https://www.b4x.com/android/forum/t...ation-of-rdc-remote-database-connector.61801/

Example from the tutorial:
B4X:
Sub GetRecord (id As Int)
   Dim req As DBRequestManager = CreateRequest
   Dim cmd As DBCommand = CreateCommand("select_animal", Array(id))
   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

You must create a new RequestManager for each request.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I add Msgbox because the log didn't work.

This is new code
B4X:
Sub Test
   reqM.Initialize(Me, Main.PUB_CONN_STR)
   Private cmd As DBCommand
   cmd.Initialize
 
   cmd.Name = "send_bnk1"
   cmd.Parameters = Array As Object(1,2,3)
        
   Wait For (reqM.ExecuteCommand(cmd,"send_bnk1")) JobDone(j As HttpJob)
   If j.Success Then
        Log(1)
   Else
        Log(0)
   End If
   Log("finished")
End Sub

On new codes
1) RequestManager only use in 1 request
2) No MsgBox

Still on log windows there was nothing. Even the Log(""finished") never came out, seem that Wait for didn't even work, but the data insert OK on the database server.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
That's right, I am using old version & so far has no problem until using Wait For.

I will try new version then. Thanks for the support.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
When something is not working as you expect, you should provide all the relevant information. The fact that you are using an old version of the client is of course relevant.
When there is an error, I thought all relevant information has been supplied.

Now, I have changed to jRDC2, it got error
<pre> com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@1a96883 -- timeout at awaitAvailable()</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>

I saw in the server, command took 20009ms, no wonder it got an error.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I think I know the reason, but to make sure I will check again before creating new thread.
Probably, this is the main reason I still use old jRDC because new jRDC2 is not compatible with my database server and will create this error when used it.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
You were right, sorry for my mistake.

It was from database server not from jRDC2. I am still using Firebird 2.5 & Firebird 3.0.

When using Firebird 3.0 with jRDC/jRDC2, there is some configuration in jRDC's/jRDC2's config file that need to be set & some setting in Firebird Server too otherwise it will caused a super slow response.

Now everything works as expected. Thanks for your help.
 
Upvote 0
Top