B4J Question B4J Sinhala Unicode issue

I have a MySQL database in which some columns contain "Sinhala Unicode" texts. I'm using the JDBCSQL Library to connect this MySQL database with my B4J application.

Here is the table structure:

MYSQL:
CREATE TABLE `tbl_tax_arpa_acres` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `arpa` text CHARACTER SET utf8 COLLATE utf8_sinhala_ci DEFAULT NULL,
  `arpa_agent` text CHARACTER SET utf8 COLLATE utf8_sinhala_ci DEFAULT NULL,
  `paddy_acres` double(10,2) DEFAULT NULL,
  `high_land_acres` double(10,2) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

I have changed the database character set to 'utf8' and the collation to 'utf8_unicode_ci'. My jdbcURL is configured as follows:

jdbc url:
Private jdbcUrl As String = "jdbc:mysql://serverIP/mydatabase?characterEncoding=utf8&autoReconnect=true"

When I run the app, the log displays the Unicode characters correctly, but the labels, TextFields, etc., show characters like "හපුà¶à¶½à·š."

Why is this happening?
 
Solution
I think perhaps you need to recreate the table tbl_tax_arpa_acres.
Try this sql:
B4X:
CREATE TABLE `tbl_tax_arpa_acres` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `arpa` varchar(100) DEFAULT NULL,
  `arpa_agent` varchar(100) DEFAULT NULL,
  `paddy_acres` double(10,2) DEFAULT NULL,
  `high_land_acres` double(10,2) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Screenshot 2023-09-05 181719.jpg
 
Upvote 0
I have checked the database using Navicat, and it looks okay to me. You can see that the log is showing the Unicode correctly, but the label is different.

This is the code I've used

B4X:
Sub getARPAacres As ResumableSub
    Dim SenderFilter As Object = connection.mysql.ExecQueryAsync("SQL", "SELECT * FROM tbl_tax_arpa_acres", Null)
    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As JdbcResultSet)
    If Success Then
        Do While rs.NextRow
            lbl_high_land.Text=rs.GetString("arpa_agent")
            Log(rs.GetString("arpa_agent"))
        Loop
        rs.Close
        Return True
    Else
        Log(LastException)
        Return False
    End If
End Sub


and the connection

B4X:
    Private jdbcUrl As String = "jdbc:mysql://serverIP/database?useUnicode=yes&haracterEncoding=utf-8&autoReconnect=true"


Database structure,

B4X:
CREATE TABLE `tbl_tax_arpa_acres` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `arpa` varchar(100) CHARACTER SET latin1 DEFAULT NULL,
  `arpa_agent` varchar(100) CHARACTER SET latin1 DEFAULT NULL,
  `paddy_acres` double(10,2) DEFAULT NULL,
  `high_land_acres` double(10,2) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


Screenshot 2023-09-06 175144.jpg
 
Upvote 0
Thank you for pointing it out.

I have changed it to

B4X:
    Private jdbcUrl As String = "jdbc:mysql://serverIP/Database?characterEncoding=utf8&useUnicode=yes"

but still no changes.

Anyway. Thank you for your help :)
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I think perhaps you need to recreate the table tbl_tax_arpa_acres.
Try this sql:
B4X:
CREATE TABLE `tbl_tax_arpa_acres` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `arpa` varchar(100) DEFAULT NULL,
  `arpa_agent` varchar(100) DEFAULT NULL,
  `paddy_acres` double(10,2) DEFAULT NULL,
  `high_land_acres` double(10,2) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
Upvote 1
Solution
Top