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 "à·„à¶´à·”à¶à¶½à·š."
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;