In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Warm Tip: to see the high-definition no-code picture, please open it with your mobile phone and click the picture to enlarge.
1. Problem description
Use Impala JDBC to insert Chinese characters into the Kudu table, the inserted Chinese string is garbled, and the Chinese string is truncated.
two。 Problem recurrence
Test environment:
CDH5.12.0Kudu1.4.0ImpalaJDBC41_2.5.35
1. Test with ImpalaJDBC code, test code
Static String JDBC_DRIVER = "com.cloudera.impala.jdbc41.Driver"; static String CONNECTION_URL = "jdbc:impala://ip-172-31-10-118:21050/default"; public static void main (String [] args) {Connection con = null; ResultSet rs = null; PreparedStatement ps = null; try {Class.forName (JDBC_DRIVER); con = DriverManager.getConnection (CONNECTION_URL); String insertsql = "insertinto my_first_table values (46, 'Test Chinese characters')" Ps = con.prepareStatement (insertsql); ps.execute (); ps.close (); ps = con.prepareStatement ("select* from my_first_table order by id asc"); rs = ps.executeQuery (); while (rs.next ()) {System.out.println (rs.getLong (1) + "\ t" + rs.getString (2));} catch (Exception e) {e.printStackTrace () } finally {try {/ / close rs, ps and con rs.close (); ps.close (); con.close ();} catch (SQLException e) {/ / TODO Auto-generated catch block e.printStackTrace ();}
two。 Insert test data into the Kudu table, such as "test", "test Chinese", "test Chinese characters"
String insertsql = "insert into my_first_table values (44, 'test')"; String insertsql = "insert into my_first_table values (45, 'test Chinese')"; String insertsql = "insert into my_first_table values (46, 'test Chinese characters')"
The following is the data inserted in the test order
Reproduce the problem by doing the above.
3. Solution method
Modify the insert statement in the program to change the single quotation mark of the inserted string to double quotation mark
String insertsql = "insert into my_first_table values (51,\" Test Chinese characters\ ")"; String insertsql = "insert into my_first_table values (52,\" Test Chinese\ ")"; String insertsql = "insert into my_first_table values (53,\" Test\ ")"
Re-insert test data into Kudu after modification: "Test Chinese characters", "Test Chinese", "Test"
The query using Hue is displayed as follows:
The Kudu display of Chinese string insertion is normal.
4. Remarks
1. Using the latest JDBC driver on Cloudera's official website, there is also the above problem when inserting Chinese characters.
Download address: https://downloads.cloudera.com/connectors/impala\_jdbc\_2.5.38.1058.zip
two。 It is normal to insert a Chinese string through Impala-shell
[172.31.10.118in 21000] > insert into my_first_table values (66 'insert Chinese characters'); Modified 1 row (s), 0 row error (s) in 0.11s [172.31.10.118row error 21000] > select * from my_first_table where id=66 +-+-+ | id | name | +-+-+ | 66 | insert Chinese characters | +-+-- + Fetched 1 row (s) in 0.21s [172.31.10.118row 21000] > [172.31.10.11821000] > insert into my_first_table values (77) "Test Chinese characters") Modified 1 row (s), 0 row error (s) in 0.11s [172.31.10.118in 21000] > select * from my_first_table where id=77 +-+-+ | id | name | +-+-+ | 77 | Test Chinese characters | +-+-- + Fetched 1 row (s) in 0.18s [172.31.10.118row 21000] >
Drunken whips are famous horses, and teenagers are so pompous! Lingnan Huan Xisha, under the vomiting liquor store! The best friend refuses to let go, the flower of data play!
Warm Tip: to see the high-definition no-code picture, please open it with your mobile phone and click the picture to enlarge.
Welcome to follow Hadoop practice, the first time, share more Hadoop practical information, like please follow and share.
Original article, welcome to reprint, reprint please indicate: reproduced from the official account of Wechat Hadoop
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.