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: 458
  • sql.zip
    1.5 KB · Views: 487
  • Project.zip
    207.2 KB · Views: 567
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:

yzhy-mail

Member
My PC is win10.
mysql-5.7.33-winx64

I find I have to use :
#AdditionalJar: mysql-connector-java-8.0.17 in jrdc
confi:
"JdbcUrl=jdbc:mysql://localhost/b4x?serverTimezone=CST6CDT"

Use EREl's b4j server ,I can get it
RemoteServer is running (12/07/2021 09:58:11)
Connection successful.


In this example I use the client.
But I can get this:
*** mainpage: B4XPage_Created
*** mainpage: B4XPage_Appear
*** mainpage: B4XPage_Resize [mainpage]
ResponseError. Reason: Not Found, Response: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing //rdc. Reason:
<pre> Not Found</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>
ERROR: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing //rdc. Reason:
<pre> Not Found</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>
 

yzhy-mail

Member
Hi Aguilar
I learn JRDC2 from your example.It is very helpful to me .
There is a issue when i run the app.When I had editd the text discription and checed it ok.The app crashed.
I changed the IP for my server only. Other funtion is ok.
Because I spent lot of time,but I didn't find where is wrong.
Please help me!

*********************
my confi:
******************
DriverClass=com.mysql.cj.jdbc.Driver
JdbcUrl=jdbc:mysql://**.102.**.**:3306/b4x?characterEncoding=utf8&serverTimezone=CST6CDT
User=root
Password=**
#Java server port
ServerPort=**

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 (?, ?, ?, ?, ?)
 

yzhy-mail

Member
Hi Aguilar

Oh, I got it !
add `value`=? for sql sentence
sql.updateEvents = UPDATE B4X.events SET `month`=?,`event_type`=?,`description`=?,`value`=? WHERE `id` = ?

Could you please refreash you post in sql sentence .It's helpful for other !
Thank you so much !
 

José J. Aguilar

Expert
Licensed User
Hi yzhy-mail:

Thanks for testing and for the feed-back.
I've downloaded the example from the forum, and I don't get any error updating the description.
I've checked the config.properties too and the line contains the 'value' part. Not sure if you have deleted it making some test or something like that.
 

yzhy-mail

Member
In the first post:

spoiler:sql sentences

See there !

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 (?, ?, ?, ?, ?)
 

José J. Aguilar

Expert
Licensed User
Hi Hikari:

You can do it in the B4XPageData module, line 35
B4X:
pmDate.SetStringItems(Array("January", "February", "March"))
 

Hikari

Member
pmDate.SetStringItems(Array("January", "February", "March"))
[/code]
Oh I already tried adding months in that array, what I meant is when I create a new event, there are only three months specifically "January" "February" and "March" as an option, how can I add it there?
 

Hikari

Member
Screenshot_20211215-031427.jpg


Is it possible to add months here or edit this form? I'm just clarifying my concerns for my additional preference and future works. I hope someone will answer my question.

Thanks in advance!
 
Top