Arabic text displaying in webapp without db change

2019-07-18 21:35发布

When a user enters arabic name and password I am supposed to retrieve data for that user.In java I am using utf-8 encoding I am supposed to retrieve data in the form of arabic text from the database.The database I am using is sql server 2005. and the column is set as varchar instead of nvarchar.Since the database is pointing to production. I could not change the column type to nvarchar. Is there any way to convert the ???? text retrieved from database into arabic text without making changes to DB. Can anyone help on this.

Bhoomesh

5条回答
乱世女痞
2楼-- · 2019-07-18 21:35

Not sure but probably you can convert the utf-8 to ANSI and store in the varchar column. While reading convert it back to utf-8.

I don't know if its possible or not but try googling.

查看更多
爷的心禁止访问
3楼-- · 2019-07-18 21:43

How were you storing the text in the database in the first place? Fundamentally, it sounds like you should be changing the database. If you're using varchar with a non-Unicode collation, then you're either limited to storing text which fits with that collation or you've got to use horribly unreliable and fundamentally "wrong" conversions which treat text as binary data.

Even if it's possible to do this for some cases, you may well find that there will be other cases which simply fail.

Talk to your database administrators, explaining that the schema is fundamentally wrong - in order to support full Unicode, you require a schema change. You'll have to go through this eventually, so you might as well save yourself nasty hacks in the meantime.

查看更多
甜甜的少女心
4楼-- · 2019-07-18 21:47

You can try to use prefix N for inserting strings into db. Like this: N'some text'.

查看更多
混吃等死
5楼-- · 2019-07-18 21:52

There's also UTF-7, which uses only US-ASCII chars. Using this, you might stay away from code page problems.

查看更多
Deceive 欺骗
6楼-- · 2019-07-18 22:00

I do not know much more about java,but your porblem is more general.

I think if the characters stored using incorrect encoding (the column is ANSI and the input is UTF8), then I do not recommend you to convert it back to UTF8 even if there is a way, but it is better to solve it from the database side.

查看更多
登录 后发表回答