Jsp for MySql and the Chinese Questions

  Abstract: MySql and for the Chinese Jsp questions 


  Let me first of all not to google, I found all changed gbk gb2312 or what. 
  In order to completely solve the problem of Chinese, all my encoding utf8 are, on the issue of utf8 few people talked about. 
  I mysql configuration has become this: 

  Show variables like 'character_set%'; 

  | Character_set_client | latin1 | 
  | Character_set_connection | latin1 | 
  | Character_set_database | utf8 | 
  | Character_set_results | latin1 | 
  | Character_set_server | utf8 | 
  | Character_set_system | utf8 | 

  This time the data is inserted in jsp?, Mysql run from the command line with a statement on the normal display. 

  Then 
  Set names utf8; 
  Show variables like 'character_set%'; 
  +————————–+———————- ———————+ 
  | Variable_name | Value | 
  +————————–+———————- ———————+ 
  | Character_set_client | utf8 | 
  | Character_set_connection | utf8 | 
  | Character_set_database | utf8 | 
  | Character_set_results | utf8 | 
  | Character_set_server | utf8 | 
  | Character_set_system | utf8 | 

  After this command line can also insert, the insert or jsp? Command-line error is that the data is too long, certainly not that type. 

  Heard jdbc driver should also be converted into a character, I did not find a way to expert advice. 



  Mysql use ISO characters to be stored, displayed Chinese GBK JSP use, so it is necessary to remove the deposit and in the process, even if you have to use utf8 is the same codec 

  Reference Procedure: 
  Public String toGBK (String input) ( 
  Try ( 
  Byte [] bytes = input.getBytes ( "ISO8859-1"); 
  Return new String (bytes, "GBK"); 
  ) Catch (Exception ex) ( 
  ) 
  Return input; 
  ) 
  / / Transfer to the ISO code GBK 
  Public String toISO (String input) ( 
  Try ( 
  Byte [] bytes = input.getBytes ( "GBK"); 
  Return new String (bytes, "ISO8859-1"); 
  ) Catch (Exception ex) ( 
  ) 
  Return input; 
  ) 



  On the original code is netBeans GBK is, I relied on. Always thought that it is UTF-8. 


  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , , , ,

Releated Java Articles

Comments

Leave a Reply