Skip to content

JDBC Connecting to Oracle from Iran (i.e. Farsi) or any other Unknown Locale

September 14, 2010

Thanks to Nasim Kabi, here is a small code that fixes Oracle JDBC issues which prevents connecting to Oracle DB if you are in an unknown locale.

public class FixOracleFarsiLocalization {
    public static void fixTheBug() {
        try {
            Class clazz = Class.forName("oracle.sql.converter.CharacterSetMetaData");
            Field territoryField = clazz.getDeclaredField("territory");
            Map territoryMap = (Map) territoryField.get(clazz);
            territoryMap.put("IR", "SAUDI ARABIA");
            territoryMap.put("fa", "SAUDI ARABIA");
            Field languageField = clazz.getDeclaredField("language");
            Map languageMap = (Map) languageField.get(clazz);
            languageMap.put("fa", "ARABIC");
        } catch (Exception ex) {
            Logger.getLogger(FixOracleFarsiLocalization.class.getName()).log(Level.SEVERE, "Exception", ex);

From → java

  1. mohammad permalink

    where we should put this function in our application

    best regards

  2. abbaspour permalink

    After loading JDBC driver and before connecting.

  3. vahid permalink

    Thanks Mr.Abbaspour,
    but my connection management is on Spring’s control, how can I tell Spring to run this method, after loading JDBC and before connecting?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: