Android Example [B4XPages] jRDC2 + MySql CRUD + Login

Hi all:


I'm starting (at last) to work with B4XPages, so I've started to adapt the B4XPages + B4XDrawer example.
I think I’ve seen more examples with php + mysql, but no projects with Jrdc2.

Maybe the dummy data and the UI are too basic, but you can get some ideas.

What do we need?
- A mysql database. You can use XAMPP, LARAGON or any other project to set it up. See attached a sql file to import in your database. The database name will be B4X.
- B4J to create the jRDC2 server
- B4A 9.9+ to support B4XPages. As always, you should update B4A to the last versión (10.5 when this post have been write)

Steps:
- Import the sql file to you database. You can use phpMyAdmin, HeidiSQL, etc…
- Configure jRDC2 server. Open the attached B4J file and change your user and password in the config file.
- Open B4A, and in the jRDC2 class, change the rdcLink const to match the IP of the computer where you’re running the jRDC2 server (B4J)
B4X:
Sub Class_Globals
    'CHANGE THE IP TO MATCH YOUR B4J SERVER
    Private const rdcLink As String = "http://192.168.1.131:8090/rdc"
End Sub
- To add, edit... we will use B4XPreferencesDialog. You should use the Form Builder to build the forms. It's important that the key values match with database's fields names, due to we will construct a map from the rs returned from the db, and it will be easier to work this way, passing this map to the B4XPreferences dialog.

I've commented the code the best I can.
If you think there are some mistakes or you know some way to improve the example, you're welcome to do it.
I've tried to make the B4J project too, but I've never used B4J and I get too many errors. If someone want to do it, we will learn something more. (or B4i)
EDIT: Updated project and now it works with B4J and B4A (maybe in B4i)

The password for all the users is: 1234 (stored as md5)

sql.Login = SELECT * FROM B4X.users WHERE `username` = ? AND `password` = md5(?)
sql.getEvents = SELECT * FROM B4X.events WHERE `month` = ? AND `id_user` = ?
sql.updateEvents = UPDATE B4X.events SET `month`=?,`event_type`=?,`description`=? WHERE `id` = ?
sql.deleteEvents = DELETE FROM B4X.events WHERE `id` = ?
sql.addEvents = INSERT INTO B4X.events(`id_user`, `month`, `event_type`, `description`, `value`) VALUES (?, ?, ?, ?, ?)
 

Attachments

  • jRDC_B4J.zip
    5.4 KB · Views: 356
  • sql.zip
    1.5 KB · Views: 377
  • Project.zip
    207.2 KB · Views: 437
Last edited:

José J. Aguilar

Expert
Licensed User
I'm impressed. After all, "converting" the project to B4J it's been easier than I thought. (Well, that’s why B4XPages were created)

Problems I'm finding in B4J:
- KVS.Initialize(File.DirInternal,"kvs"): unknown member dirinternal.
solved using XUI.DefaultFolder

- PrefDialogEvents.Initialize(Root , "Events", 90%x, 300dip): unknown member perxtocurrent
Solved changing 90%x to a fixed dip. PrefDialogEvents.Initialize(Root , "Events", 300dip, 300dip). Not sure (yet) the best way to achieve this.

- If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip...
Solved adding
#if B4A
If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
#end if

***Edited: some more changes to adapt to B4J
_Click event is _MouseClicked in B4J, so you have to do this way (thanks @angel_ and B4XPleroma project)
B4X:
#if B4J
Private Sub lblDelete_MouseClicked (EventData As MouseEvent)
#else
Private Sub lblDelete_Click
#end if

Not working yet: (EDIT: UPDATED PROJECT IN FIRST POST TO WORK IN B4J and B4A)
- The + sign not showing
- The edit and delete labels not working...

Work in progress....

TIP: you can learn a lot of interesting things with B4XPleroma client.

1612301298319.png
 
Last edited:
Top