---
title: "How To Update NLS_SORT Parameter Value When Using 10g Thin JDBC Driver ? [ID 469"
author: "libin123"
date: "2010-12-17T10:05:35Z"
tags: []
categories: ["数据库"]
slug: "how-to-update-nls-sort-parameter-value-when-using-10g-thin-jdbc-driver-id-469"
draft: false
lastmod: "2010-12-17T10:05:35Z"
id: 845245
url: "https://dbua.iteye.com/blog/845245"
---

## 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](https://support.oracle.com/CSP/main/article?cmd=show&type=BUG&id=3967004)).   Here is sample of  a Logon trigger (change &lt;user&gt; 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; /`