Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving Arabic text from MSSQL NVarchar column

I am making a Library Management System, I am trying to add arabic support in my project but I am facing difficulties as follows,

  1. when inserting data in SQL through Query i.e Insert into book_info values(25, N'جاوا', N'Author',N'Publisher',2014,N'Subject',50,N'Language','Latest',5) The List of Columns in book_info is as follows

    • Book ID(int)
    • Book Title(NVarchar(50))
    • Author(NVarchar(50))
    • Publisher(NVarchar(50))
    • Publish Year(int)
    • Subject(NVarchar(50))
    • Price(int)
    • Language(NVarchar(50))
    • Edition(NVarchar(50))
    • Part(int)

    Therefore when I execute this query through my Project, SQL Management Studio Shows some Encoded Characters like 'مجتبیٰ' in place of Arabic Characters, and not only in SQL Management Studio but also when Selecting data in project. Note: these values in query are taken from textfield through .getText() function

  2. What if we just skip the first problem by executing the query in SQL Management Studio, by doing this the first problem is temporarily resolved as SQL Management Studio is showing arabic characters when selecting the data but again when we select it from our software and show it in Textfield by Getting data from ResultSet like "TextF.setText(ResultS.getNString())" it shows "??????" in the text field in place of Arabic Characters.

like image 324
MMujtabaRoohani Avatar asked Dec 06 '14 10:12

MMujtabaRoohani


1 Answers

Your database definition, query, and SQL instance is fine. The issue you are having is with reading the string from the database into java.

I think Java is trying to read your nvarchar text as ASCII characters, when they are actually in Unicode. The result is garbled looking text. I think when you read the text from the database, you'll need to ensure you're reading as Unicode.

If you can post your code, I could probably pinpoint what is causing you issues.

like image 173
ChrisG Avatar answered Nov 20 '22 02:11

ChrisG