当我从终端插入所有好的:插入城镇价值观(113,’?eskT?ebov’,22,“测试”,真实);但是当我通过JDBC手动保存时:java.sql.Connection conn = null;Statement stmt = null;Class.forName(com.mysql.jdbc.Driver);...
当我从终端插入所有好的:
插入城镇价值观(113,’?eskáT?ebová’,22,“测试”,真实);
但是当我通过JDBC手动保存时:
java.sql.Connection conn = null;
Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/a2b", "root", "root");
stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO towns VALUES (200, '?eská T?ebová', 22, 'test', true);");
…或者来自Hibernate的持久化对象:
String townName = new String("?eská T?ebová".getBytes(), "UTF-8");
townDao.persist(new Town(townName, CountryCode.AQ, "test", true));
……或者使用PreparedStatement:
PreparedStatement addTown = null;
String addTownPrepared = "INSERT INTO towns VALUES (1100, ?, 22, 'test', true)";
addTown = conn.prepareStatement(addTownPrepared);
addTown.setString(1, townName);
addTown.executeUpdate();
……我在MySQL 5.5上看到了?eskáT?ebová
我在数据库中有许多名为Göppingen,Würzburg,Kolín的城市 – 问题不在于所有非拉丁符号.
========================================
我在Lubuntu 14.04下.
show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
在pom.xml中我有
<integration-test.jdbc.url><![CDATA[jdbc:mysql://localhost:3306/a2b?useUnicode=yes&characterEncoding=UTF-8]]></integration-test.jdbc.url>
我的桌子:
CREATE TABLE towns (
id BIGINT AUTO_INCREMENT ,
name VARCHAR (256) NOT NULL ,
country SMALLINT NOT NULL ,
source VARCHAR (256) ,
is_active BIT DEFAULT 1 ,
PRIMARY KEY (id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8;
Workbench的屏幕截图:
解决方法:
注意URL到数据库!您确定要编辑您认为的URL吗?
在我的pom.xml中,我有:
< integration-test.jdbc.url>,< test.jdbc.url>和< jdbc.url>.
我需要更改< jdbc.url>从jdbc:mysql:// localhost:3306 / a2b到<![CDATA [jdbc:mysql:// localhost:3306 / a2b?useUnicode = yes& characterEncoding = UTF-8]]>
本文标题为:Java,MySQL:我保存了“ČeskáTřebová”,但保存了“?eskáT?ebová”(来自终端一切都很好)
基础教程推荐
- SpringBoot 如何使用sharding jdbc进行分库分表 2022-11-01
- Java利用过滤器实现完善登录功能 2023-05-24
- 图文详解Java的反射机制 2023-04-13
- Java中随机函数变换的示例详解 2023-04-23
- Java JSch远程执行Shell命令的方法 2022-10-30
- SpringBoot2.0解决Long型数据转换成json格式时丢失精度问题 2023-01-08
- Java Redis Redisson配置教程详解 2023-03-31
- 使用spring jpa 如何给外键赋值 2023-01-24
- 详解SpringMVC中拦截器的概念及入门案例 2023-02-11
- SpringCloud hystrix断路器与全局解耦全面介绍 2023-06-23