B4J Question Would I be able to use jRDC2?

Darren69

Member
Licensed User
Longtime User
Hi there, I am trying to decide the best way to implement something and thought I would ask the forum for help.

I have an application that sends images and some other information to a server built in b4J using the serilaizer, this information is stored in a sql database, but I also want to be able to pull information from the database to a user running an application written using b4i, at first I thought about using HTTP get requests to pull the information from the database and sending it back using the serilaizer, but now I am thinking jRDC2 would be easier, but I really dont want to be running a server app for the database unless I have to as the database is constantly being updated by users so would rather one application handling both the incoming images and also serving out the information to users

anyone have any thoughts on this?

thanks in advance

Darren
 

Harris

Expert
Licensed User
Longtime User
and some other information
Meaning table data?

pull information from the database
Implied meaning table data...

I am thinking jRDC2 would be easier, but I really dont want to be running a server app for the database

jRDC2 would be easier... UNLESS - you like to complicate your code required, support for new things and your life.

Try it, you are on the right track. Only you can decide.

For storing images on disk (server) from device, you may use HTTP. Not saying this is correct (sub below) - but it works for me...

B4X:
Sub SendtoSever(dir As String, pk As String, FileName As String,pt As String)
    If File.Exists(dir,FileName) Then
      ' continue
    Else
        ToastMessageShow(" Sorry - Zip Not Found: "&FileName, False)
        Log(" Sorry - Zip Not Found: "&FileName)
        Return     
    End If

        Dim j As HttpJob
        Dim out As OutputStream
        out.InitializeToBytesArray(0)
        Dim In As InputStream = File.OpenInput(dir, FileName)
'        Log(" send to server file: "&FileName)
        File.Copy2(In, out)
        
        Dim lastSlash As Int = FileName.LastIndexOf("/")
        If lastSlash > -1 Then
            FileName = FileName.SubString(lastSlash + 1)
        End If
        Dim su As StringUtils
        Dim j As HttpJob
        j.Initialize("file", Me)
        If pk = 1 Then  'campics
            j.PostBytes( Main.srvlinkcam & "?type=file&name=" & su.EncodeUrl(FileName, "UTF8")&"&pk="&pk&"&where="&pt,     out.ToBytesArray)
        End If

        If pk = 2 Then  ' inspect pdfs
            j.PostBytes( Main.srvlinkins & "?type=file&name=" & su.EncodeUrl(FileName, "UTF8")&"&pk="&pk&"&where="&pt,     out.ToBytesArray)
        End If

        If pk = 3 Then ' ecmdata files zips
            j.PostBytes( Main.srvlinkecm & "?type=file&name=" & su.EncodeUrl(FileName, "UTF8")&"&pk="&pk&"&where="&pt,     out.ToBytesArray)
       '     ToastMessageShow("Sending Zip File to Server: "&FileName,False)

        End If
            
End Sub
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
I'd recommend using jRDC2 which of course uses OkHTTPUtils2.
https://www.b4x.com/android/forum/t...ation-of-rdc-remote-database-connector.61801/

There is nothing wrong with splitting the workload into 2 programs, one to import the images and the other to export the images.
You could also use jRDC2 to import the images too if you like.
jRDC2 is much safer than accessing the database directly using SQL especially if it will be used over the Internet.
 
Upvote 0

Darren69

Member
Licensed User
Longtime User
Thank you both -

yeah, I am sending information from users in to a database storing images as blobs and the other information in to a table - but then want to pull information from the same database to other users when requesting. I was not sure if using jRDC2 I needed to run a separate database server, or if it can all be done within a single app, as I plan on running it all from a rather low powered mini PC.

I will noodle around with this at the weekend - but thanks for the replies.

Darren
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
Thank you both -

yeah, I am sending information from users in to a database storing images as blobs and the other information in to a table - but then want to pull information from the same database to other users when requesting. I was not sure if using jRDC2 I needed to run a separate database server, or if it can all be done within a single app, as I plan on running it all from a rather low powered mini PC.

I will noodle around with this at the weekend - but thanks for the replies.

Darren

If you are using a client server database like MySQL (Innodb engine), sharing the database between 2 applications will work just fine. The MySQL MyISAM engine uses extremely fast table locks whereas its Innodb engine uses slower but more granular row locks which makes for better concurrency if you have more than 20 or more connections at a time.

If you were using SQLite, which is not a client server database, will slow down by locking people out if there are a lot of writes from different users at the same time because its transactions uses database locks and will force other users to wait (even readers) while the record is being updated.

Hope this helps.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
With this mod (warning: self-promoted mod), you can use SQLite as DB storage and you would not need a separate DB server: https://www.b4x.com/android/forum/threads/modded-jrdc2-w-sqlite-support-and-more.85578/#content

If there was only 1 update process running and nothing else (no reads), then I'd say fine use Sqlite.
Of if the database was doing only reads, then Sqlite will work just fine too.

But Darren69 wants to use the same database to store images (blobs) and at the same time serve up information from another table in the same database to other users. This means he has 2 processes running on the same database. One that is storing blobs and another than retrieves text(or images?) from a different table. If he has a lot of images to store, or if they are large images, then the Sqlite database will be locked for a long duration during the updates/inserts which means the 2nd process will not be allowed to read the other table to serve the data to his users. Sqlite will only work if the image updates are infrequent and fast otherwise the database locking will prevent the other process from running.

Now if Darren69 can clarify he is only updating the images infrequently, say 2 or 3 images a minute and it takes less than a second to save the image, then Sqlite may work fine. (Or if he is storing small images that take only a fraction of a second to store.) But if he is updating 60 large images a minute and it takes 1 second to store each image (depending on image size), then the 2nd process will be locked out of the database even though all it is doing is reading from a different table.

BTW, I have tried your jRDC2 mod for Sqlite and it works just great. Thanks for the mod. :)
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
You know, you 2 peeps (@Widget and @OliverA ) constantly (in other posts) banter back and forth of the merits of each DB type.

My 2 cents...
SQLite, which is not a client server database
Use an industrial DB on a server (MySQL, MSSQL, postgres, etc.) and leave the light weight DB for the device (SQLite).

If you have a server - then why the heck not? IMHO, SQLite was meant for (and works just fine) on mobile devices.
This is how I use these and don't have any issues to contend with. Lord knows there are other things to consume our valuable time.

Yes, we could continue this conversation forever - yet why frustrate the issue?
And besides - what the hell do I know anyways... (with a grain of salt).

Thanks
 
Upvote 0

Darren69

Member
Licensed User
Longtime User
thanks again for more indepth conversation about this -

the images are really small, and are sent to the database via serializer along with some other information that is all stored in a table. Another user can request the row from the database using a unique row ID number that would just send them that row of the database, this would then populate their local app's database with the information.

I will look in to an industrial DB server, I do have a freenas box running somewhere, that i know i can use to serve SQL databases to, I just have not tried it yet.

again thanks, lots of things to try out when i next get some sit down time to program!

Darren
 
Upvote 0
Top