Android Question sql utf8

catyinwong

Active Member
Licensed User
Longtime User
I have already set the language of the sql server to be in utf8. When I update the data, the characters seem to be saved properly because I can select the correct rows using ExecQuery. But the jdbcresultset.getstring method doesn't read the right string and the strings become ???? when being read. Any suggestion to fix the problem?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can add the charSet parameter to the connection string: charSet=UTF8

It does change the ResultSet charset (you can see it in the debugger) though the returned string is wrong. Maybe the database is not configured properly.

As a workaround you can store the text encoded with base64 string and decode it on the client.
 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User
You can add the charSet parameter to the connection string: charSet=UTF8

It does change the ResultSet charset (you can see it in the debugger) though the returned string is wrong. Maybe the database is not configured properly.

As a workaround you can store the text encoded with base64 string and decode it on the client.

is there an example code for base64 encoding and decoding?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Use Encryption Library.

B4X:
    Dim teststring As String = "dhhjdfhshf jjkdjjk hsdjk fhsj kh fjksdf hs"
    Dim b64 As Base64
    Dim base64str As String = b64.EncodeStoS(teststring,"UTF8")
    Log($"Base64 (write it to DB) = ${base64str}"$)

and decode the string back

B4X:
' Read the base64 from db
    ' and decode it
    Dim decoded As String = b64.DecodeStoS(base64str,"UTF8")
    Log($"Base64 decoded = ${decoded}"$)
 
Upvote 0
Top