B4J Question using the mysql in a tcpserver

Addo

Well-Known Member
Licensed User
i am planing to build a tcpserver using b4j this part is fine but there is a few things in my brain that confuse me

i will hold about 900 clients on the port each client will be able to insert delete stuff in the mysql database

now i am asking what should i do in the sql part ? should i give each client its own sql like for example

B4X:
Sub Class_Globals

    Private astream As AsyncStreams
    Private Mserv As servermanager
    Dim clientsql As SQL
End Sub

or i should create a module that connect to sql one time and do the querys inside it with all of this number of clients ?
 

DonManfred

Expert
Licensed User
Longtime User
Setup a jRDC2 and connect all the Clients to it.
JRDC2 does the Connection to the Database and query/insert/update the data based on the Request.
i guess you can idetify each client and use client specific values on the data writte to the DB.
 
Upvote 0

Addo

Well-Known Member
Licensed User
The clients will have a different databases to connect so maybe each request will connect to a multiple databases
I will search more in the forum to get the better approach I am still learning the b4j usage
 
Upvote 0

Addo

Well-Known Member
Licensed User
i will do that i am just practice on basics to fully understand what i am doing

i have created a module like following which makes me ask this question
B4X:
Sub Class_Globals
Private fx As JFX

End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub


Public Sub garabcountrys(dbname As String, dbtable As String, colnm As String)
Dim SQL1 As SQL
Dim sqltext As String
Dim cursor As ResultSet
SQL1.Initialize2("com.mysql.jdbc.Driver","jdbc:mysql://localhost/"&dbname&"?characterEncoding=utf8","root", "root")

cursor = SQL1.ExecQuery("SELECT * FROM "&dbtable&"")


Do While cursor.NextRow
Log(cursor.GetString(colnm))
Loop

cursor.Close
SQL1.Close
End Sub

the goal is i wanted to know if i call garabcountrys sub so often based on client request it would be a problem ?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
the goal is i wanted to know if i call garabcountrys sub so often based on client request it would be a problem ?
At minimun, use pooling. See the source for jRDC2 for pool usage. Also, check out ABMaterial. The ABMFeedback app that is included as an example has a DBM code module that uses pooling. Note: You do not have to use the web component of the jServer library in order to use pooling. You should open up your database (either via SQL object or pooling) once at program start. Also, if you want to create a TCP server instead of a web server, then check out the FTP server and how it handles multiple connections.

Links:
jRDC2: https://www.b4x.com/android/forum/t...-rdc-remote-database-connector.61801/#content
ABMaterial: https://www.b4x.com/android/forum/threads/abmaterial-framework-for-webapps.60072/#content
FTP server: https://www.b4x.com/android/forum/t...d-with-socket-and-asyncstreams.74320/#content
 
Upvote 0
Top