Results 1 to 2 of 2
  1. #1
    romina is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default Convert some special characters stored in a MySql

    I am trying to convert some special characters stored in a MySql DB for display in Java.
    Among the things I would like to convert are "ễ" to "ễ", "ç" to "", "ü" to "", etc.
    My jdbc connection is
    Java Code:
    jdbc:mysql://DBL_URL/NAME?requireSSL=false&useUnicode=true&characterEncoding=UTF-8
    I'v tried with no luck:
    Java Code:
    byte[] stringBytes = dbString.getBytes();
    String str = new String(stringBytes , "UTF-8");
    A SHOW VARIABLES LIKE 'character_set%'; in mySql produces this:
    Java Code:
    character_set_client utf8
    character_set_connection utf8
    character_set_database latin1
    character_set_results utf8
    character_set_server latin1
    character_set_system utf8
    character_sets_dir C:\Program Files\MySQL\MySQL Server 4.1\share\charsets/
    Thanks

  2. #2
    trill is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    According to this website, latin1 is this charset: ISO-8859-1
    Supported Encodings

    And my charset for my MySql DB is character_set_database latin1.

    So. Whatever I did to make it UTF-8 didn't work. It was still latin1 coming out. Basically, characterEncoding=UTF-8 and String str = new String(stringBytes , "UTF-8"); didn't work.

    So, I finally assumed that it was latin1 coming back all the time. Here's the code that converts it to UTF-8:
    Java Code:
    	private String convertStringFromLatin1ToUTF8(String stringForconversion) {
    		try {
    			String stringToConvert = stringForconversion;
    			byte[] convertStringToByte = stringToConvert.getBytes("ISO-8859-1");
    			return new String(convertStringToByte, "UTF-8");
    		} catch (UnsupportedEncodingException e) {
    			System.out.println"convert String FAILED: " + stringForconversion + "<br/>");
    			return stringForconversion;
    		}
    	}
    Greetings.

Similar Threads

  1. Stored Procedures
    By geeta_ravikanti in forum JDBC
    Replies: 1
    Last Post: 04-22-2008, 02:34 AM
  2. special characters
    By ravian in forum New To Java
    Replies: 2
    Last Post: 11-16-2007, 01:28 PM
  3. show special symbol using its Unicode character
    By christina in forum AWT / Swing
    Replies: 1
    Last Post: 07-25-2007, 09:21 AM
  4. Special characters in text fields
    By Felissa in forum Web Frameworks
    Replies: 0
    Last Post: 06-27-2007, 04:47 PM
  5. Stored Procedures with java
    By Albert in forum JDBC
    Replies: 4
    Last Post: 06-08-2007, 05:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •