Display special characters using System.out.println(使用 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...
我的第一个猜测是:
- 您的源文件编码可能有误(您是否使用了 Maven 之类的构建工具?可能还需要在那里设置源编码),
- 您的控制台编码可能有误(您是在 Windows 下吗?默认的命令行控制台默认不是 UTF,它依赖于本地,但您可以在注册表中稍微设置一下它的编码)
- 您的数据库编码可能不正确(表编码是什么,您能检查一下吗?)
这篇关于使用 System.out.println 显示特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 System.out.println 显示特殊字符
基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 从 python 访问 JVM 2022-01-01
