问题描述
- flyway迁移数据中文乱码
- 项目的编码方式为UTF-8
mian方法代码:
import org.flywaydb.core.Flyway;public class App { private static String url = ""jdbc:mysql://localhost:3306/miaomiao""; private static String user = ""root""; private static String password = ""root""; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Flyway flyway = new Flyway(); flyway.setEncoding(""UTF-8""); // 设置sql脚本文件的编码 flyway.setDataSource(url user password); flyway.migrate(); }}
sql脚本(mysql,排序规则为:utf8_general_ci):
CREATE TABLE `hehe` ( `id` BIGINT(20) NOT NULL AUTO_INCREMENT `name` VARCHAR(50) NOT NULL PRIMARY KEY (`id`))COLLATE='utf8_general_ci'ENGINE=InnoDBAUTO_INCREMENT=1;INSERT INTO `hehe` (`name`) VALUES ('aa');INSERT INTO `hehe` (`name`) VALUES ('bb');INSERT INTO `hehe` (`name`) VALUES ('阿才');INSERT INTO `hehe` (`name`) VALUES ('大飞');
结果为
1 aa
2 bb
3 ??
4 ??网上查了好久也没解决,请大家帮忙看看问题出在哪?
解决方案
插件的xml里面的配置文件中
<!-- 设置sql脚本文件的编码 -->
UTF-8
解决方案二:
能把你的flyway配置的插件晒出来嘛?
时间: 2024-10-03 12:23:19