어느 가을날의 전환점

JAVA|JDBC 클라이언트 프로그램에서 NLS_LANG관련 설정 변경하는 방법 본문

Database/Oracle

JAVA|JDBC 클라이언트 프로그램에서 NLS_LANG관련 설정 변경하는 방법

어느가을빛 2011. 8. 10. 13:39
PURPOSE
JDBC CLIENT PROGRAM 에서 NLS_LANGUAGE , NLS_TERRITORY 등
을 바꾸는 방법을 sample 을 통해서 알아 봅니다.

Explanation

다음 예제에서는 먼저 DB 에 default 로 설정되어 있는 
NLS_LANG 관련 설정사항들을 보여주고 그 다음 US 로 설정을 
바꾼후에 바뀐 NLS_LANG 관련 parameter 들의 값을 보여 줍니다.

Example



NLSTest.java 파일

import java.sql.*;
import java.util.*;

public class NLSTest {


public static void main (String args []) throws SQLException {

Connection conn;
Statement stmt;
ResultSet rset;

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

System.out.println ("Locale not set"); 

conn = DriverManager.getConnection ("jdbc:oracle:thin:@krint-5.kr.oracle.com:1525:ora920", "scott", "tiger");
System.out.println(); 
stmt = conn.createStatement ();
// Get Properties
System.out.println("Java Properties:") ; 
System.out.println("property user.language: " + System.getProperty("user.language"));
System.out.println("property user.region: " + System.getProperty("user.region"));
System.out.println(); 
// Get Locale information
System.out.println("Java Locale:") ; 
System.out.println("Locale getDefault = "+Locale.getDefault());
System.out.println("Locale getCountry = "+Locale.getDefault().getCountry());
System.out.println("Locale getLanguage = "+Locale.getDefault().getLanguage());
System.out.println(); 
// Select the NLS parameters
System.out.println("Current session NLS settings:") ;
rset = stmt.executeQuery ("select * from nls_session_parameters ");
while(rset.next())
System.out.println(rset.getString(1) + " = " + rset.getString(2));
conn.close();

System.out.println(); 
System.out.println ("Set the default Locale to america"); 
Locale.setDefault(Locale.US);

conn = DriverManager.getConnection ("jdbc:oracle:thin:@krint-5.kr.oracle.com:1525:ora920", "scott", "tiger");
System.out.println(); 
stmt = conn.createStatement ();
// Get Properties
System.out.println("Java Properties:") ; 
System.out.println("property user.language: " + System.getProperty("user.language"));
System.out.println("property user.region: " + System.getProperty("user.region"));
System.out.println(); 
// Get Locale information
System.out.println("Java Locale:") ; 
System.out.println("Locale getDefault = "+Locale.getDefault());
System.out.println("Locale getCountry = "+Locale.getDefault().getCountry());
System.out.println("Locale getLanguage = "+Locale.getDefault().getLanguage());
System.out.println(); 
// Select the NLS parameters
System.out.println("Current session NLS settings:") ;
rset = stmt.executeQuery ("select * from nls_session_parameters ");
while(rset.next())
System.out.println(rset.getString(1) + " = " + rset.getString(2));
conn.close();


}


실행 결과


E:\temp>java NLSTest
Locale not set

Java Properties:
property user.language: ko
property user.region: KR

Java Locale:
Locale getDefault = ko_KR
Locale getCountry = KR
Locale getLanguage = ko

Current session NLS settings:
NLS_LANGUAGE = KOREAN
NLS_TERRITORY = KOREA
NLS_CURRENCY = ₩
NLS_ISO_CURRENCY = KOREA
NLS_NUMERIC_CHARACTERS = .,
NLS_CALENDAR = GREGORIAN
NLS_DATE_FORMAT = RR/MM/DD
NLS_DATE_LANGUAGE = KOREAN
NLS_SORT = BINARY
NLS_TIME_FORMAT = HH24:MI:SSXFF
NLS_TIMESTAMP_FORMAT = RR/MM/DD HH24:MI:SSXFF
NLS_TIME_TZ_FORMAT = HH24:MI:SSXFF TZR
NLS_TIMESTAMP_TZ_FORMAT = RR/MM/DD HH24:MI:SSXFF TZR
NLS_DUAL_CURRENCY = ₩
NLS_COMP = BINARY
NLS_LENGTH_SEMANTICS = BYTE
NLS_NCHAR_CONV_EXCP = FALSE

Set the default Locale to america

Java Properties:
property user.language: ko
property user.region: KR

Java Locale:
Locale getDefault = en_US
Locale getCountry = US
Locale getLanguage = en

Current session NLS settings:
NLS_LANGUAGE = AMERICAN
NLS_TERRITORY = AMERICA
NLS_CURRENCY = $
NLS_ISO_CURRENCY = AMERICA
NLS_NUMERIC_CHARACTERS = .,
NLS_CALENDAR = GREGORIAN
NLS_DATE_FORMAT = DD-MON-RR
NLS_DATE_LANGUAGE = AMERICAN
NLS_SORT = BINARY
NLS_TIME_FORMAT = HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT = DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT = HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT = DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY = $
NLS_COMP = BINARY
NLS_LENGTH_SEMANTICS = BYTE
NLS_NCHAR_CONV_EXCP = FALSE

E:\temp>


#출처 : http://forums.oracle.com/forums/thread.jspa?threadID=477100&tstart=120
Comments