Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

impala jdbc insert chinese string have a problem

avatar
Explorer

the table DDL as :

create table mid.user_info(id int,name string,address string,email string,insert_time timestamp,primary key(id)) partition by hash(id) partitions 6 stored as kudu;

my java code such as:

 

import java.sql.*;
import java.time.LocalDateTime;

public class test {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.cloudera.impala.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:impala://impala.db.com:8006/mid;AuthMech=0;UseNativeQuery=1;", "impala", "impala");
        String sql = "upsert into user_info(id, name, address, email, insert_time) values (?,?,?,?,?)";
        PreparedStatement statement = conn.prepareStatement(sql);
        statement.setInt(1,106);
        statement.setString(2, "张三");
        statement.setString(3, "上海");
        statement.setString(4, "John@xyz.com");
        statement.setTimestamp(5, Timestamp.valueOf(LocalDateTime.now()));
        statement.addBatch();
        statement.executeBatch();
        statement.close();
        conn.close();
    }
}

 

I get a bad result when I execute it,The Chinese string appears to be truncated:

result.jpg

How can I solve this problem?

please!

3 REPLIES 3

avatar
Explorer

hi @ShankerSharma ,How can I solve this problem?

avatar
Expert Contributor

As upsert is not SQL-92 syntax, the Impala JDBC driver does not currently support it.   However, we are currently testing a newer version of the JDBC driver and hope to support upsert in the near future.  For the time being, please break these statements into a combination of insert and update statements.

avatar
New Contributor

This is not the essence of the problem, what the question actually wants to ask is the problem of inserting data with Impala JDBC, Chinese strings being truncated and garbled.