Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why JDBC sets the NLS_LANGUAGE and NLS_TERRITORY?

843859Jun 16 2006 — edited Jun 19 2006
Hi All,

I have a question regarding JDBC, NLS_LANGUAGE and NLS_TERRITORY.

Simple program to connect to database from a client running JDK 1.4.2_10 to get the results from an oracle table

import java.net.URL;

import java.sql.*;
import java.lang.*;
import oracle.jdbc.driver.*;

class Select {

public static void main(String argv[]) {
try {

oracle.jdbc.driver.OracleLog.startLogging();
//oracle.jdbc.driver.OracleLog.setLogVolume(3);
// Create a URL specifying an ODBC data source name.
System.out.print("before DriverManager");
Class.forName("oracle.jdbc.driver.OracleDriver");
// Connect to the database at that URL.
System.out.print("before DriverManager \n");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@hostname:SID", "user", "passwd");
DatabaseMetaData meta = con.getMetaData();
// gets driver info
System.out.println("JDBC driver version is " + meta.getDriverVersion() + "\n");


System.out.print("After DriverManager \n");
// Execute a SELECT statement
Statement stmt = con.createStatement();

//ResultSet rs = stmt.executeQuery("SELECT att1, att2 from table1");
System.out.println("Result count ");

while (rs.next())
{
System.out.print("att1 <" rs.getString(1) "> att2 <"+rs.getString(2)+">\n");
}
stmt.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

Server Details
Windows 2003
Oracle 11i
(nls_database_parameters)
NLS_LANGUAGE = AMERICAN
NLS_TERRITORY= AMERICA
NLS_CHARACTERSET=UTF8

Client Setup

Windows XP
JDK 1.4.2_10
NLS_LOCALE=en_us
NLS_LANG not set
Control Panel-> Regional and Language options
Regional Options Tab
"English(United Kingdom" is selected in the first drop down list
Location is set to United Kingdom

The program didnt return any rows at all :(

The debug information has the following sql statements before executing the actual query and after connecting to the database

DRVR SQLS SQL: "ALTER SESSION SET NLS_LANGUAGE = 'ENGLISH'"
DRVR SQLS SQL: "ALTER SESSION SET NLS_TERRITORY = 'UNITED KINGDOM'"
and for NLS_DATE, etc but not NLS_CHARACTER_SET

FIX 1

I was able to get the results successfully by

modiying the program put the following statements

stmt.executeQuery("ALTER SESSION SET NLS_LANGUAGE = 'AMERICAN'");
stmt.executeQuery("ALTER SESSION SET NLS_TERRITORY = 'AMERICA'");


FIX 2

I was also able to see the results if Ichange the regional settings in the control panel to "English(United States)" and location to "United States"



Questions

1) Why JDBC sets these variables when it doesnt need to actually do it?

2) Why it ignores the variable NLS_LANG set in the environment?

Thanks & Regards
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2006
Added on Jun 16 2006
1 comment
1,526 views