How To Update NLS_SORT Parameter Value When Using 10g Thin JDBC Driver ? [ID 469

Applies to:

JDBC - Version: 10.2 to 11.1.0
Information in this document applies to any platform.

Goal

When using 10gR2 or 11g  Thin JDBC driver, the session NLS_SORT parameter is not set with the expected value (for instance 'CROATIAN'  instead of 'BINARY').
How to make sure that your session uses the expected session  NLS_SORT  parameter value?

Solution

Here are three options to set the NLS_SORT session  parameter with the 10gR2  Oracle JDBC Thin driver.

  • Using java locale setting
    The value of the used NLS_SORT parameter depends on the locale that has been set when running the java program. Therefore by setting the language and the region on startup of the java process the NLS_SORT parameter can be influenced. To do so start the java program as following:
    java  -Duser.lang=en  -Duser.region=US  <jdbc_program>


  • Set NLS_SORT within your Java application
    Add code to your java program that alters the database session when retrieving a connection to connect to the database. The code would look like:
    ...
    String s_alter = "alter session set NLS_SORT=BINARY";
    Statement stmt = null;
    stmt = p_connection.createStatement();
    stmt.execute( s_alter );
    ...


  • Set the value via a trigger when connecting to the database server
    To make sure that this parameter NLS_SORT is set for every connection done to the database, you can also use a database trigger that sets the value after the users connect. Note that this 'trigger option'  will work  when accessing database server  with  the JDBC Thin driver (not with the OCI  JDBC driver, you can refer to  the enhancement request Bug 3967004).   Here is sample of  a Logon trigger (change <user> with the name of the actual user for which the parameter should be set):
    CREATE OR REPLACE TRIGGER <user>.TRG_ONLOGON_CHANGE_NLS_SORT
    AFTER LOGON ON <user>.SCHEMA
    BEGIN
      execute immediate 'ALTER SESSION SET NLS_SORT = BINARY';
    END;
    /

 

你可能感兴趣的:(java,oracle,jdbc)