HIVE通过jdbc连接,使用insert into插入中文数据乱码
[2023-03-21 21:36:31] Fetched row string:
1 � �xxQ܀/ Pl� � hmf@yahoo.com 15652996964 210302199608124861 f45W,3632734� BWP018930705 210302199608124861 BWP018930705 f45W,3632734� H21157232 9839487602 117 6227612145830440 اK��
20230321一晚上尝试以下解决办法:
1、百度搜索,答案最多的就是修改数据库、表、分区字符集,未解决问题,放弃
2、url增加useUnicode=true&characterEncoding=UTF-8,未解决问题,放弃
3、终于找到一个解决办法
insert into 中文数据 ,先对中文数据转换字符编码 ,然后插入数据,再读取数据就没有问题了
String insertSql="INSERT INTO regre_one.hive_varchar (id,aes, sm4, sm4_a, email, phone, ssn, military, passport, intelssn, intelpassport, intelmilitary, intelganghui, inteltaitonei, credit_card_short, credit_card_long, job) VALUES (1,'小芬', '北京xx网络技术有限公司', '北京市', 'hmf@yahoo.com', '15652996964', '210302199608124861', '武水电字第3632734号', 'BWP018930705', '210302199608124861', 'BWP018930705', '武水电字第3632734号', 'H21157232', '9839487602', '117', '6227612145830440', '高级测试工程师')";
Statement statement=conn.createStatement();
statement.execute(new String(insertSql.getBytes(), "iso8859-1");
执行结果:
[2023-03-21 21:39:15] Fetched row string:
1 小芬 北京xx网络技术有限公司 北京市 hmf@yahoo.com 15652996964 210302199608124861 武水电字第3632734号 BWP018930705 210302199608124861 BWP018930705 武水电字第3632734号 H21157232 9839487602 117 6227612145830440 高级测试开发工程师