Closed ningpengtao-coder closed 4 years ago
@PengtaoNing Thanks for reporting the issue! Could you provide some sample data and use case where you met the problem in our JDBC driver?
@PengtaoNing Thanks for reporting the issue! Could you provide some sample data and use case where you met the problem in our JDBC driver?
POST _bulk {"create":{"_index":"sql_data","_id":1}} {"name":"中文1"} {"create":{"_index":"sql_data","_id":2}} {"name":"中文2"} {"create":{"_index":"sql_data","_id":3}} {"name":"中文3"} {"create":{"_index":"sql_data","_id":4}} {"name":"中文4"} {"create":{"_index":"sql_data","_id":5}} {"name":"中文5"}
correct
kibana: POST _opendistro/_sql { "query": "SELECT * FROM sql_data where name = '中文1'" }
correct
curl: curl -XPOST "http://localhost:9200/_opendistro/_sql" -H 'Content-Type: application/json' -d'{ "query": "SELECT * FROM sql_data where name = \"中文1\""}'
incorrect
jdbc: Connection connection = DriverManager.getConnection(jdbcElasticsearchURL);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM sql_data where name = '中文1'");
default charset: ISO-8859-1
The JDBC SQL statement is incorrect because the SQL statement is encoded to:
SELECT * FROM sql_data where name = '????1'
@PengtaoNing Thanks for the info! Will try to reproduce from my side.
The issue has been fixed with #68. Feel free to reopen it.
ApacheHttpTransport line 263 HttpPost.setEntity when creating a StringEntity without specifying the encoding, ISO-8859-1 is used by default and no encoding can be set such as UTF-8.
I am using version 1.4.0.0
1.4.0.0:
ApacheHttpTransport:
request.setEntity(new StringEntity(body));
StringEntity:
ContentType:
public static final ContentType DEFAULT_TEXT = TEXT_PLAIN;
public static final ContentType TEXT_PLAIN = create( "text/plain", Consts.ISO_8859_1);
expected:
request.setEntity(new StringEntity(body,ContentType.APPLICATION_JSON));