1

I'm using spring for android. I want to create registration form in my android app. The users maybe fill out the form with utf-8 format but when data send to server and store in MySQL database I find ?????? in my database field.table's column type set to utf8_general_ci. My question is: Do I need to set something for content type in php page OR I need set UTF-8 in my android code? What should I do for both of them? Here is my code that I'm using: I did same as here

File cacheDirectory = context.getFilesDir();
tmpFile = new File(cacheDirectory.getPath() + "/" + "avatar.png");
Resource file = new FileSystemResource(tmpFile);

MultiValueMap<String, Object> formData = new LinkedMultiValueMap<String, Object>();
formData.add("firstName", registerFields[0]);
formData.add("lastName", registerFields[1]);
formData.add("userName", registerFields[2]);
formData.add("file", file);

HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.MULTIPART_ FORM_DATA);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new        HttpEntity<MultiValueMap<String, Object>>(formData, requestHeaders);


RestTemplate restTemplate = new RestTemplate(true);

restTemplate.getMessageConverters().add(
     new GsonHttpMessageConverter());
restTemplate.getMessageConverters().add(
new StringHttpMessageConverter());
ResponseEntity<Success[]> response = restTemplate.exchange(url, HttpMethod.POST,       requestEntity,Success[].class);
return response.getBody();

Edit: Solved problem with UTF-8 I just added this line into my config.php file and problem solved

mysql_query("SET character_set_results=utf8 , character_set_client=utf8 , character_set_connection=utf8 , character_set_database=utf8 , character_set_server=utf8",$con);

Edit: Not solved the problem

Misagh Aghakhani
  • 1,023
  • 2
  • 13
  • 29

1 Answers1

1

Debugging here will be your friend. Some things to be aware of:

  1. Check that whatever you are using to view the data isn't the issue. Does MySQL store ????? or it your app just showing you ????
  2. Check content formatting on your connection to MySQL, this is a likely culprit. (You could test this by simply writing an app to push data into your database without going over the net)
  3. Check your web application is handling the reading in UTF-8. For example in an older version of JBoss I worked with the embedded apache container read strings from the connection in the default character set of the machine the server was running on (which wasn't utf-8)
BenG
  • 130
  • 6
  • thx yes MySQL store ??????.when i change content type in my android code to requestHeaders.setAccept(Collections.singletonList(new MediaType("application", "json"))); instead of requestHeaders.setContentType(MediaType.MULTIPART_ FORM_DATA); and I send data without image my problem goes away. content type in php page is set to application/json – Misagh Aghakhani Feb 20 '13 at 06:48
  • Are you also setting the content encoding to utf-8 when you send your request? – BenG Feb 20 '13 at 09:18