Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';t在MySQL中插入UTF-8西里尔字母字符串_Java_Mysql_Character Encoding - Fatal编程技术网

Java Can';t在MySQL中插入UTF-8西里尔字母字符串

Java Can';t在MySQL中插入UTF-8西里尔字母字符串,java,mysql,character-encoding,Java,Mysql,Character Encoding,我明白了: Properties properties= new Properties(); properties.setProperty("user", login); properties.setProperty("password", password); properties.setProperty("useUnicode","true"); properties.setProperty("characterEncoding","UTF-8"); conn = DriverManager

我明白了:

Properties properties= new Properties();
properties.setProperty("user", login);
properties.setProperty("password", password);
properties.setProperty("useUnicode","true");
properties.setProperty("characterEncoding","UTF-8");
conn = DriverManager.getConnection("jdbc:mysql://" + host + "/" + db, properties);

String message = "Раунд " + nextRoomId;

Data.db.executeUpdate("INSERT INTO chat(message) VALUES('" + message + "')");
mysql配置:

Раунд 338
表和数据库是完全utf-8编码的,我不能从java插入西里尔字母字符串,因为我的表中有错误的编码字符串


我做错了什么?

尝试将代码更改为:

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

编辑器(IDE)和javac编译器使用相同的编码吗?
javac
选项是
-编码UTF-8
。否则,字符串文字的转换错误。您可以尝试使用
“\u0420\u0430\u0443\u043D\u0434”
。如果这样做行得通,那么.java的编码就有问题。

尝试这样做,没有帮助:(如果你尝试打印
消息
变量,你得到了什么?这对我来说非常好。我有项目的所有编码,MySQL数据库到utf-8,但是仍然面临西里尔字符的问题。使用getBytes()神奇的事情发生了。谢谢你编辑器使用的是utf-8,没有BOM,我如何用utf-8编码编译代码?我试过这个:javac-encoding=utf-8 Main.java,但是-encoding标志无效我试过javac-encoding utf8 Main.java-效果很好,谢谢你,maan!Gratulations,utf-8我看到的越来越多。你使用哪种构建系统?在maven中很简单:pom.xml,编译器插件。在ant中,它是javac任务的一个属性。对于纯TAK:
javac-encoding=UTF-8…
。我只使用标准java编译器和记事本++:)如果你想要简单,可以尝试一下NetBeans IDE;是的,eclipse有点过载。顺便说一句,我经常使用记事本+,喜欢知道发生了什么。但像自动完成、javadoc、JSE源代码、maven集成、vcs等都是无与伦比的。
Properties properties= new Properties();
properties.setProperty("user", login);
properties.setProperty("password", password);
properties.setProperty("useUnicode","true");
properties.setProperty("characterEncoding","UTF-8");
conn = DriverManager.getConnection("jdbc:mysql://" + host + "/" + db, properties);

String message = "Раунд " + nextRoomId;
String encMessage = new String(message.getBytes(), "UTF-8");

Data.db.executeUpdate("INSERT INTO chat(message) VALUES('" + encMessage + "')");