B4J Question jRDC2 connect Two or More MySQL databases

zabayin

Member
Licensed User
Longtime User
I already read .. Erel Answer from
https://www.b4x.com/android/forum/threads/jrdc-how-to-connect-to-multiple-database.59930/#content

But as i'm new member to b4x and not expert in java ... modification of RDCHandler is hard for me.
I do Erel answer but i can't success.

This is my jRDC config.properties file
B4X:
#DATABASE CONFIGURATION
DriverClass=com.mysql.jdbc.Driver
JdbcUrl=jdbc:mysql://45.32.xxx.xx/ns_abc8?characterEncoding=utf8

#Local
User=root
Password=password

#Java server port
ServerPort=17178


How to Edit RDCHandler, RDCConnector ? Could anyone help me for something. Many Thanks to You.
 

jimmyF

Active Member
Licensed User
Longtime User
I found, with MySql, that you can simply use the format:
database.Tablename in queries rather than simply Tablename.
e.g.
Instead of
B4X:
Select * from MyTable
use:
B4X:
Select * from db.MyTable

Very Important: The databases must be on the same server, same port number and the same user rights.

Incredible, but it works!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

zabayin

Member
Licensed User
Longtime User
A simple solution is to run multiple instances of jRDC2. Each one configured with a different port and a different database.
If i run multiple instances of jRDC2 .... can i faced with heavy consumption of RAM ? one instance of jRDC took 40+ MB of RAM and i think it should not be more than 10 instances of 512 MB VPS Ram. Am i right sir ?
 
Upvote 0

zabayin

Member
Licensed User
Longtime User
I found, with MySql, that you can simply use the format:
database.Tablename in queries rather than simply Tablename.
e.g.
Instead of
B4X:
Select * from MyTable
use:
B4X:
Select * from db.MyTable

Very Important: The databases must be on the same server, same port number and the same user rights.

Incredible, but it works!
That was awesome !!! i don't know about it and i'll test it. Thank you bro.
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
Hi zabayin,

If you only have one or two databases then having a couple of instances of jRDC running is no big deal.

Using different ports can also be handy if you want remote access to a db to be different from a local access.

I added the config file name as a command line argument do I can set the ports and queries for two different instances.

I can load 7200 40 field records to a remote connection over WiFi and it's virtually instantaneous.

I used the modded version of jRDC server made by OliverA who added some stuff to make it work with sqLite.

Modded jRDC Server by olivera for sqLite


If you want to start a server at boot I used the Task Scheuler with the following command lines:

Program/Script => W:\MyProgramFiles_W\Java_13_0_02\bin\javaw (Or you can use java in lieu of javaw if you want a windows command process
Arguments => -jar jRDC_sqLite.jar Port_17178_RemotePmon.properties
Start In => W:\MyProgramFiles_W\PowerMonProgs\pmonDB_uServerJRDC\jRDC_sqLite\jRDCv2_sqLite\Objects\

The file Port_17178_RemotePmon.properties is selected in this case and has the following contents:

B4X:
#Lines starting with '#' are comments.
#Backslash character at the end of line means that the command continues in the next line.

#jRDC CONFIGURATION
#Be warned. A wrong IP address here will keep the server from starting correctly.
#IPAddress=192.168.1.148
#Java server port
ServerPort=17178

#DATABASE CONFIGURATION
#SQLite
DriverClass=com.sqlite.JdbcUrl
JdbcUrl=jdbc:sqlite:G:\\PSM_Server_DB\\psmdb_winSvr.db

#SQLite specific. Set CreateFile to create file if it does not exist.
CreateFile=False


#SQL COMMANDS

sql.getPwrDataLastRaw_0001=SELECT * FROM getPwrDataLastRaw_0010_View
sql.getPwrDataWithAlarmsLast_0001=SELECT * FROM getPwrDataWithAlarmsLast_0001_View
sql.getPwrDataLast_10_Stats=SELECT * FROM getPwrDataLast_0010_Stats_N2000_View
sql.getPwrDataWithAlarms_Raw_N7200_Ascn=SELECT * FROM getPwrDataWithAlarms_Raw_N7200_Ascn_View
sql.getPwrDataWithAlarmsStartEnd_NLimit7200=SELECT * FROM getPwrDataWitAlarmsRawWithTimeCrit WHERE julianDateUTC BETWEEN ? AND ? LIMIT 7200

You can see that the port is set at line 8.

With different ports you can use different firewall rules for each instance/port.

Have a look at the following post which I found helpful:

Additional Info

Best regards
Rob

Best regards

Rob
 

Attachments

  • jRDCv2_sqLite.zip
    12.1 KB · Views: 379
Upvote 0

NagyLajos

Member
Licensed User
Thank's @Erel!
I modified what you uploaded a bit so that you can use an unknown number of databases.
B4X:
Sub AppStart (Args() As String)
    DatabaseRead
    dbs = SqlList
    srvr.Initialize("")
    Connectors = srvr.CreateThreadSafeMap
    For Each db As String In dbs
        Dim Con As RDCConnector
        Con.Initialize(db)
        Connectors.Put(db, Con)
    Next
.
.
.
.
.
End Sub

Sub DatabaseRead
    Dim dbRes As ResultSet
    configx = LoadConfigMap                                ' Load config
    Dim jdbc As String = configx.Get("JdbcSrv")            'Get server config
    SqlList.Initialize
    sHost = configx.Get("DriverClass")&jdbc&"/"            'Build Host
    If sSql.IsInitialized=False Then
        sSql_Init                                        'Init database
    End If
    dbRes=sSql_Query("SELECT table_schema AS 'Database' FROM information_schema.TABLES where left(table_schema,2)='XY' GROUP BY table_schema;")
'    Sleep(500)                        'Wait for query'
    Do While dbRes.NextRow
        SqlList.Add(dbRes.Getstring("Database"))  
    Loop
    sSql.Close                        'Close database'
End Sub

Please modify 'WHERE' clause.

Regards
Lajos
 
Last edited:
Upvote 0
Top