B4J Tutorial [jRDC2] Raspberry Pi MySQL accessed by B4J UI application using jRDC2

rwblinn

Well-Known Member
Licensed User
Hi,

wanted to learn more about jRDC2. Let me share testing jRDC2 accessing a MySQL database, running on a Raspberry Pi (RPi), via a B4J UI application.

Raspberry Pi MySQL Setup
  • MySQL running on RPi with IP 192.168.0.58.
  • RDC folder on the RPi /home/pi/b4j/rdc
Below the steps of creating a MySQL table called 'notes', inserting some records, select records.
The MySQL commands have been entered in a MySQL session via Putty Terminal to access the RPi.

B4X:
login as: pi
pi@58:~ $ mysql -uroot -hlocalhost -p 
mysql> CREATE DATABASE notes;
mysql> CREATE USER 'notesuser'@'localhost' IDENTIFIED BY 'nu';
mysql> GRANT ALL PRIVILEGES ON notes.* TO 'notesuser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> exit
pi@58:~ $ mysql -unotesuser -hlocalhost notes -p
mysql> CREATE TABLE notes (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,description VARCHAR(50),content VARCHAR(255), created TIMESTAMP DEFAULT NOW());
mysql> INSERT INTO notes(description,content) VALUES ('Note 1', 'The content of note 1.');
mysql> INSERT INTO notes(description,content) VALUES ('Note 2', 'The content of note 2.');
mysql> SELECT * FROM  notes;
+----+-------------+------------------------+---------------------+
| id | description | content  | created  |
+----+-------------+------------------------+---------------------+
|  1 | Note 1  | The content of note 1. | 2016-05-26 11:32:18 |
|  2 | Note 2  | The content of note 2. | 2016-05-26 11:32:29 |
+----+-------------+------------------------+---------------------+
B4J Class jRDC2
The reference used.
Changes to original code:
Config.properties file: Set the location to File.DirApp instead if File.DirAssets to be flexible in changing the configuration with rebuild the class.

Read the config.properties file located in the dirapps folder.

Example extracts output running jRDC2 on the RPi
B4X:
...
jRDC is running (version = 2.11)
...
Command: query: select3, took: 1623ms, client=192.168.0.4
Command: query: select3, took: 44ms, client=192.168.0.4
B4J UI application RDCClientUI
Functionality
* CRUD (Create, Read, Update, Delete) operations from the Remote MySQL database (defined in jRDC2 config.properties)
* Show the records in a tableview, set initial tableview message (Java API method using JavaObject).
* Toastmessage dialog when waiting for database operation to complete (Library jRLDialogs8).
* Toolbar used for the buttons (Java API methods using JavaObject).
* Set styling for buttons & toolbar (Library CSSUtils).
* Set styling for tooltips (external CSS file in the dirassets folder)

Class DBRequestManager
Changes to original code:
Modified Image handling by setting conditional defines for B4A and B4J.

Source
Read the attached source code which is well documented.

Screenshot
The application is running well.
Hint: On the RPI 3 turn the WLAN power off (define in /etc/rc.local: iw dev wlan0 set power_save off).

upload_2016-5-27_11-6-31.png


B4J Bridge

While developing, the B4J Bridge was running on the RPi. Ensure to copy the config.properties to the tempjars folder.
Hint: Create the tempjars folder as user pi, which makes it easier to copy the update config.properties file.

v2016.05.27
 

Attachments

Top