使用 System.out.println 显示特殊字符 [英] Display special characters using System.out.println

查看:26
本文介绍了使用 System.out.println 显示特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从我的网络服务向我的数据库发送或显示带有特殊字符的文本时遇到问题.在我的日食中,我已将字符编码设置为 UTF-8,但它仍然不允许我显示字符.例如一个简单的打印,如下面的代码

I'm having trouble sending or displaying text with special characters from my webservice to my database. On my eclipse I have set the character encoding to UTF-8 but it still doesn't let me display the characters. For example a simple print like the code below

String test ="привет"; 
System.out.println(test);

String test ="привет";
String query = "insert into communication (`test`) VALUES ('"+ test +"');
PreparedStatement preparedStmt1 = con.prepareStatement(query);
preparedStmt1.executeUpdate();

控制台上的结果,如果我将其发送到我的数据库是 ??????.如何让它在控制台上正确显示并希望在数据库中显示

The result on the console and if I send this to my database is ??????. How do I get this to display correctly on the console and hopefully in the database

推荐答案

是的,它是 XXI.世纪以来,我们仍在努力解决诸如字符编码之类的问题...

Yeah, its the XXI. century and we're still struggling with things like character encoding...

我的第一个猜测是:

  1. 您的源文件编码可能有误(您是否使用了 Maven 之类的构建工具?可能还需要在那里设置源编码),
  2. 您的控制台编码可能有误(您是在 Windows 下吗?默认的命令行控制台默认不是 UTF,它依赖于本地,但您可以在注册表中稍微设置一下它的编码)
  3. 您的数据库编码可能不正确(表编码是什么,您能检查一下吗?)

这篇关于使用 System.out.println 显示特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆