B4J Library [class] jRDC - B4J implementation of RDC (Remote Database Connector)

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
jRDC version 2 is available here: https://www.b4x.com/android/forum/threads/class-jrdc2-b4j-implementation-of-rdc-remote-database-connector.61801/

Please start with this thread if you are not familiar with RDC: Remote Database Connector (RDC) - Connect to any remote DB

RDC was implemented before B4J was available. It was implemented in Java.
jRDC is a port of RDC server to B4J.
The main advantage of jRDC over RDC is that you can modify the source code. For example you can easily add support for SSL or connect to multiple databases.
The performance of both servers is the same.
Note that B4J creates executable jars so you can start the server with a double click or from the command line with:
B4X:
java -jar jRDC.jar
There are some differences between the behavior and configuration of jRDC and RDC:
  • On the client, the server link should end with /rdc. For example:
    B4X:
    reqManager.Initialize(Me, "http://192.168.0.6:17178/rdc")
  • You need to set the jdbc jar with the #AdditionalJar attribute (on the server). There is no jdbc_driver folder.
  • jRDC always returns 0 for the affected rows fields in batch requests.
From the client side you just need to add /rdc to the link and it should work.

There is another difference related to the way nulls are handled. It shouldn't be a problem with new jdbc drivers.

jRDC v1.00 is attached. It fixes an issue related to blobs.
 

Attachments

Last edited:

marcick

Well-Known Member
Licensed User
Hi.
I was thinking to replace the actual RDC with this one. The goal is to add in each RDC command a custom text parameter that the server shows in the console. This would help me to identify the customers just watching the console.
First question is .. I can't see the console ... which is the best way to implement it ?
Second difficulties is how to manage the custom text, but I think I should look the SUb "LoadSQLCommands" and understant it.
 

Erel

Administrator
Staff member
Licensed User
First question is .. I can't see the console ... which is the best way to implement it ?
You will see the logs when:
1. Run it from the IDE.
2. Run it from the command line with: java -jar <your jar>
 

marcick

Well-Known Member
Licensed User
oh, understood, so anything is added as log in B4J then is showed in the console. Very good, thanks
Marco
 

marcick

Well-Known Member
Licensed User
Some troubles ...
this is the code B4A side

B4X:
reqManager1.Initialize(Me, "http://100.100.100.100:17178/rdc")
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "RDC_Test"
    cmd.Parameters = Array As Object(Null)
    reqManager1.ExecuteQuery(cmd, 0, "tag1")
in config.properties I have
B4X:
sql.RDC_Test = SELECT COUNT(*) FROM `records`
But I get this error:

B4X:
(SQLException) java.sql.SQLException: Parameter index out of range (1 > number o
f parameters, which is 0).
Command: , tool: 0ms, client=82.60.232.57
Where I'm wrong ?
The same identical code (except for the "/rdc" suffix in reqmanager.initialize) is working on the "old" RDC
 

Erel

Administrator
Staff member
Licensed User
You are sending a single parameter (with the value of null) and the command doesn't expect any parameter.

Remove the line that sets cmd.Parameters or change it to:
B4X:
cmd.Parameters = Array As Object()
 

marcick

Well-Known Member
Licensed User
Perfect !

Now, when I'm at this line in SUB Handle of RDCHandler module:

B4X:
 Log($"Command: ${q}, tool: ${DateTime.Now - start}ms, client=${req.RemoteAddress}"$)

How to retrieve all the parameters of the request ?
 

Erel

Administrator
Staff member
Licensed User
Go over the code you will see where the parameters are extracted.
 

marcick

Well-Known Member
Licensed User
Me again ..
running the jar from the command line I see a log file is created that contains strings like:

B4X:
82.60.232.57 -  -  [22/Oct/2015:11:40:38 +0000] "POST /rdc?method=query HTTP/1.1" 200 - "-" "-"
Is it possible to avoid this log or eventually customize it ?
 

Erel

Administrator
Staff member
Licensed User
Please start a new thread for this and I'll explain what can be done (it is not specific to jRDC).
 

Erel

Administrator
Staff member
Licensed User
v1.00 is attached to the first post. It fixes an issue related to blobs.
 

Anser

Well-Known Member
Licensed User
There is another difference related to the way nulls are handled. It shouldn't be a problem with new jdbc drivers.
Will this break my existing B4A code?

In my code, I have many lines that check for Null For eg.
B4X:
If records(result.Columns.Get("Activity_DateTime")) = Null Then

If records(result.Columns.Get("Bill_Amt")) = Null Then
So do I have to take care of all that ?

From the client side you just need to add /rdc to the link and it should work.
If the change in my B4A code is minimal then, I am planning to move from RDC to jRDC

Regards
Anser
 

Erel

Administrator
Staff member
Licensed User
Will this break my existing B4A code?
It will most probably work exactly as before. The change is not related to Null checking. It is related to the way Null parameters are bound to the query.
It is only relevant to older jdbc drivers.
 

incendio

Well-Known Member
Licensed User
Better to move to jRDC.

I have seen its features & 1 is really obvious, security.

With RDC, user name & password,url, sql commands, etc, stored on config file with is very easy to read.
With jRDC, you can embedded in jar file or on any encrypted file.
 

Erel

Administrator
Staff member
Licensed User
With RDC, user name & password,url, sql commands, etc, stored on config file with is very easy to read.
If someone has access to the server files then nothing on the server is secure.

I agree that it is better to move to jRDC.
 
Status
Not open for further replies.
Top