0

I am a java coder and in my project, I would like to store specific font to microsoft access database. But in database their is only show "????" sign. For detail, I was used JTextField to get the String and then insert into the MS database table. But in the table field, it only show "???". Is there any method like( statement.executeUpdate() )that can show the "Zawgyi-One" font type in the database.

Hint, I get String from my textfield and insert into the ms access but it only show "????". Is there any method to change Unicode string to ASCII in java?

  • 2
    A String is a String. It doesn't have any font. You might see question marks either because you're saving Unicode chaacters not supported by the encoding used by MS Access, or because the tool you use to look at the values in the database doesn't use a fond that can display those characters. – JB Nizet Feb 21 '13 at 13:13

2 Answers2

0

It's not the font that's the problem. It's that java is storing a Unicode string (UTF-16)and MS Access thinks it ought to be ASCII and the Unicode values, being 2 bytes, don't match up to anything.

You'll need to write a little utility along the lines of:

public static String cleanString(String s) {
    String temp = Normalizer.normalize(s, Normalizer.Form.NFD);
    Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
    return pattern.matcher(temp).replaceAll("");
}

Call that on your input before storing it in the database.

WPrecht
  • 1,340
  • 1
  • 17
  • 29
  • So that how must I do to display right data in ms access. Hint, I get String from my textfield and insert into the ms access but it only show "????". Is there any method to change Unicode string to ASCII in java? – user2095528 Feb 21 '13 at 13:20
0

it's been a while since i last used ms-access. To begin with, i'm not perfectly sure ms-access supports unicode in the first place.

Assumed it does, you might look for a parameter in the jdb-odbc connection definition. What you have now is, that the multibyte Unicode character isn't recognised as such and written as several ASCII characters into the database.

Apart from this being wrong, you will run into arbitrary length problems, because for every non-ascii unicode character your string will be longer than expected, when this kind of thing happens. I once bit my teeth on a trouble ticket called "Database write fails for names with Umlaut"

:-)

To check things out you could try to write one of the (burmese?) characters into a table via the ms-access GUI and then READ the table via JDBC-ODBC.

If you actually can store the characters in ms-access, your next move would be to tweak the JDBC-ODBC connection in a way that you end up with these characters on the Java side.

shartelle
  • 95
  • 4