在jTextField中输入和显示unicode字符

时间:2011-02-18 07:45:18

标签: java unicode utf-8 jtextfield

我有java GUI程序用于在数据库中输入和显示文本,但是当我从数据库中检索回来时,我继续在jTextField中获取非英文字符的问号。

对于输入,我可以将非英文字符复制/粘贴到文本字段并正确显示(粘贴时)。数据库插入也没有任何错误。由于java是基于Unicode的,所以我希望能够顺利实现这一目标。

可能有帮助的其他信息

开发环境

操作系统:安装了所有非英文字符支持的Windows XP

爪哇

JDK 1.6 update23

后端

MySQL 5.5

编码:utf8

整理:utf8_general_ci

虽然我的应用程序是英文的,但我希望能够在字段中输入和显示utf8字符。需要一些建议。

2 个答案:

答案 0 :(得分:3)

我有类似的问题。我可以使用插入查询插入unicode字符,但是当我在Jtextfield中键入一些并按下添加按钮时,它们被插入到db corrupted中。编辑连接字符串解决了我的问题。

jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf8 

答案 1 :(得分:0)

In eclipse, Windows > Preferences > Java > Installed JRE > Select the JRE > 
Click on Edit button > set value for Default VM arguments > 

-Dfile.encoding=UTF-8

Then compile the source file and execute the program. 

If you want to display UTF-8 characters at console then therefor it, 
while running an application follow these steps.

Right Click > Run As > Run > Java Application > 
EXE Name of Java Application which you are trying to run > 
Click on Tab Common > Console Encoding > Other > UTF-8 > Apply > Run