I have problems getting data from several databases in one host, for example : dbsample_01
dbsample_02
etc...
how do i pass parameters to jrdc's config.properties?
or there are special changes to be able to access between databases?
how to get the data with the following query?
B4X:
select * from dbsample_01.table_A;
select * from dbsample_02.table_A;
this is the query in my jrdc config.properties :
SQL:
sql.list_datatable = select * from dbsample_?.table_A;
sample code from client :
B4X:
Dim strNumberDB as String = "01"
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("list_datatable", Array(strNumberDB))
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
If j.Success Then
....
End If
And the result :
B4X:
(MySQLSyntaxErrorException) com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near ''01'.table_A LIMIT 0,25' at line 1
I modify the JRDC2 Multi so we can pass the DB number instead of the DB Name.
JRDC Server (Main Sub):
Sub GetDBName (DB As String) As String
Select Case DB
Case "01"
Return "dbsample_01"
Case "02"
Return "dbsample_02"
Case Else
Return "" ' set to empty string to throw error
'Return "dbsample_01" ' default to "dbsample_01
End Select
End Sub
We can use parameter "db" to pass the DB Number value (e.g. http://127.0.0.1:17178/test?db=01) and then by using GetDBName return the actual DB Name to pass to RDC Connector.
JRDC Server TestHandler.bas:
Dim DB As String = req.GetParameter("db")
Dim connector As RDCConnector = Main.Connectors.Get(Main.GetDBName(DB))
Situation: I am currently developing an APP where I use jRDC2 (with their respective jRDC2.bas and DBRequestManager.bas in B4A) and it works PERFECT. But I need to connect with the same jRDC2 Server to multiple Databases. @Erel I published last year this version of jRDC2 Multi that supports...
Situation: I am currently developing an APP where I use jRDC2 (with their respective jRDC2.bas and DBRequestManager.bas in B4A) and it works PERFECT. But I need to connect with the same jRDC2 Server to multiple Databases. @Erel I published last year this version of jRDC2 Multi that supports...
Sub AppStart (Args() As String)
srvr.Initialize("")
Connectors = srvr.CreateThreadSafeMap
Dim dbs As List = Array("database_01", "database_02") 'read from a file
For Each db As String In dbs
Dim con As RDCConnector
con.Initialize(db)
Connectors.Put(db, con)
Next
srvr.Port = 17178
srvr.AddHandler("/test", "TestHandler", False)
srvr.AddHandler("/rdc", "RDCHandler", False)
srvr.Start
Log($"jRDC is running (version = $1.2{VERSION})"$)
StartMessageLoop
RDC Connector:
Sub Class_Globals
Private pool As ConnectionPool
Private DebugQueries As Boolean
Private commands As Map
Public serverPort As Int
Public mDBName As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (DBName As String)
mDBName = DBName
Dim config As Map = LoadConfigMap
Dim jdbc As String = config.Get("JdbcUrl")
jdbc = jdbc.Replace("$DB$", mDBName)
pool.Initialize(config.Get("DriverClass"), jdbc, config.Get("User"), _
config.Get("Password"))
#if DEBUG
DebugQueries = True
#else
DebugQueries = False
#end if
serverPort = config.Get("ServerPort")
LoadSQLCommands(config)
End Sub
Is the output from the /test URL? if so, did you include ?DBName=database_01 as part of the URL? (for example: 127.0.0.1:17178/test?DBName=database_01)
I modify the JRDC2 Multi so we can pass the DB number instead of the DB Name.
JRDC Server (Main Sub):
Sub GetDBName (DB As String) As String
Select Case DB
Case "01"
Return "dbsample_01"
Case "02"
Return "dbsample_02"
Case Else
Return "" ' set to empty string to throw error
'Return "dbsample_01" ' default to "dbsample_01
End Select
End Sub
We can use parameter "db" to pass the DB Number value (e.g. http://127.0.0.1:17178/test?db=01) and then by using GetDBName return the actual DB Name to pass to RDC Connector.
JRDC Server TestHandler.bas:
Dim DB As String = req.GetParameter("db")
Dim connector As RDCConnector = Main.Connectors.Get(Main.GetDBName(DB))
In Client app, we append the db parameter to rdc link.
B4X:
Sub CreateRequest (DB As String) As DBRequestManager
Dim req As DBRequestManager
req.Initialize(Me, rdcLink & "?db=" & DB)
Return req
End Sub
I modify the JRDC2 Multi so we can pass the DB number instead of the DB Name.
JRDC Server (Main Sub):
Sub GetDBName (DB As String) As String
Select Case DB
Case "01"
Return "dbsample_01"
Case "02"
Return "dbsample_02"
Case Else
Return "" ' set to empty string to throw error
'Return "dbsample_01" ' default to "dbsample_01
End Select
End Sub
We can use parameter "db" to pass the DB Number value (e.g. http://127.0.0.1:17178/test?db=01) and then by using GetDBName return the actual DB Name to pass to RDC Connector.
JRDC Server TestHandler.bas:
Dim DB As String = req.GetParameter("db")
Dim connector As RDCConnector = Main.Connectors.Get(Main.GetDBName(DB))
In Client app, we append the db parameter to rdc link.
B4X:
Sub CreateRequest (DB As String) As DBRequestManager
Dim req As DBRequestManager
req.Initialize(Me, rdcLink & "?db=" & DB)
Return req
End Sub
this is very easy to understand, I missed the code in the test handler of the original JRDC modification of course, including forgetting to put the database fetch code... sorry I'm not careful
once again thank you very much for your help @aeric
Is the output from the /test URL? if so, did you include ?DBName=database_01 as part of the URL? (for example: 127.0.0.1:17178/test?DBName=database_01)