B4J Question my crude solution to JRDC multiple database access


Active Member
Licensed User
Longtime User

all the desired databases should be in the same server.

JRDC2 Server side modifications
Private Sub ExecuteQuery2 (con As SQL, in As InputStream,  resp As ServletResponse) As String
    Dim ser As B4XSerializator
    Dim m As Map = ser.ConvertBytesToObject(Bit.InputStreamToBytes(in))
    Dim cmd As DBCommand = m.Get("command")
    Dim limit As Int = m.Get("limit")
    ''' my addtions starts
    Dim newcmd As  String=cmd.Name
    Dim nstat As Int =newcmd.IndexOf("|")
    If nstat>0 Then
        dbName=cmd.name.SubString2(0,nstat) & "."
    End If
    '''' my addtions end
    Dim ns As String= Main.rdcConnector1.GetCommand(newcmd)  ''' modified cmd to newcmd

    ns=ns.Replace("&",dbName)   ''' inserting dbname n place of &

Client side calling
    Dim cmd As DBCommand = CreateCommand(Starter.cDbname & "|select_groups", Array())

The desired database name is stored in Starter.cDbname
we pass the dbname in 1st parameter concatenating with a pipe (|) char to the command name (as defined is config.prop file)

in the Config.prop file prefix with & for select from &tablename , update &tablename, delete from &tablename, insert into &tablename

The above will let us to access multiple databases. I have tested the same and working perfectly.

Note : I agree this is not an efficient way but serves my purpose