±Û¾´ÀÌ :±è´öÅ 1998³â 2¿ù 07ÀÏ 08:27:48
In Reply to: ¿À¶óŬ JDBCµå¶óÀ̹ö¿¡¼ÀÇ ÇѱÛ󸮿¡ ´ëÇÑ Á¤¸®(2) posted by ³ª°æ±Ç on 1998³â 2¿ù 06ÀÏ 20:45:54:
ÀÌµé µå¶óÀ̹ö´Â À¯´ÏÄÚµå 1.2¸¸À» Áö¿øÇϸç ÀÚ¹Ù¿¡¼ÀÇ À¯´ÏÄÚµå 2.0ÀÇ ÇѱÛ
Ç¥Çö Â÷ÀÌ·Î ÀÎÇØ ¹®Á¦°¡ »ý±â´Â °ÍÀ̸ç, ¿À¶óŬ µå¶óÀ̹öÀÇ ÄÚµå º¯È¯ °úÁ¤Àº
´Ù¼Ò º¹ÀâÇÑ °ÍÀ¸·Î º¸ÀÔ´Ï´Ù.
ÇѱÛȯ°æ¿¡¼ µ¥ÀÌŸº£À̽ºÀÇ ÀÎÄÚµùÀ» 8859-1·Î ¼³Á¤ÇÏ´Â °ÍÀº ¹Ù¶÷Á÷ÇÏÁö ¾ÊÀ¸¸ç,
¸¸¾à ÀÌ¿Í °°ÀÌ ÇÏ°íÀÚ ÇÑ´Ù¸é, ¿À¶óŬ»ç³ª Àü¹®°¡¿¡°Ô ¹ß»ýÇÒ ¼ö ÀÖ´Â ¹®Á¦Á¡À»
¸ÕÀú ¹®ÀÇÇÏ¿© È®ÀιÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.
¾î·µç, µ¥ÀÌŸº£À̽º ÀÎÄÚµùÀ¸·Î´Â KSC5601 ¹× UTF8¸¸À» °í·ÁÇÏ´Â °ÍÀÌ ¹Ù¶÷Á÷Çϸç
ÀÚ¹Ù¿Í µå¶óÀ̹ö°¡ ¹®ÀÚ¿À» ±³È¯ÇÒ ¶§, ´ÙÀ½ Ŭ·¡½ºÀÇ ¸Þ½îµå¸¦ »ç¿ëÇÏ¿© À¯´ÏÄÚµå 1.2¿Í
º¯È¯ÇÏ¿© ÁÖ°í ¹Þµµ·Ï ÇϽʽÿÀ.
Á÷Á¢ »ç¿ëÇغ¸Áö´Â ¸øÇßÀ¸³ª, KSC5601ÀÇ °æ¿ì¿¡´Â ¹®Á¦¾øÀÌ µ¿ÀÛÇÑ´Ù°í µé¾úÀ¸¸ç,
¶ÇÇÑ, µ¥ÀÌŸº£À̽ºÀÇ ÀÎÄÚµù°ú NLS_LANGÀ» µÑ´Ù UTF8·Î ¼³Á¤ÇÑ ÈÄ¿¡,
ÀÚ¹Ù ÇÁ·Î±×·¥À» ¼öÁ¤¾øÀÌ ±×´ë·Î ¼öÇàÇصµ µÉ °ÍÀ¸·Î º¸ÀÔ´Ï´Ù.
¹°·Ð, ¾î¶² °æ¿ìµç À¯´Ð½º¿¡¼´Â setenv LANG koµµ ¹Ýµå½Ã ½ÇÇàÇÑ ÈÄ,
°Ë»çÇغ¸½Ã±â ¹Ù¶ø´Ï´Ù.
SQL*PLUS·Î ¾ÈµÇ´Â ÀÌÀ¯´Â »ç¿ëÇϽŠÅ͹̳¯ÀÌ KSC5601¸¸À» Áö¿øÇϱ⠶§¹®À̸ç,
UTF8À» Áö¿øÇÏ´Â Å͹̳¯»ó¿¡¼ Å×½ºÆ®Çغ¸½Ã±â ¹Ù¶ø´Ï´Ù.
(UTF8 Áö¿ø hanterm: ftp://ftp.kaist.ac.kr/hangul/terminal/hanterm/hanterm304beta )
ÀÚ¹ÙÀÇ °æ¿ì´Â ±»ÀÌ UTF8 Áö¿ø Å͹̳¯ÀÌ ÇÊ¿äÇÏÁö ¾Ê½À´Ï´Ù.
(Sysytem.out.printlnÀÌ KSC5601·Î ´Ù½Ã º¯È¯ÇØÁִϱñ)
/*
* @(#)DB.java 1.0 98/02/05
*
* Program Type: Package
*
* Purposes:
* 3. À¯´ÏÄÚµå 2.0°ú À¯´ÏÄÚµå 1.1, 1.2¿ÍÀÇ ÇÑ±Û Ç¥Çö Â÷À̸¦ º¸¿ÏÇÑ´Ù.
*
* Usage:
*
*
* Background Information for Unicode 2.0 and Unicode 1.0, 1.1, 1.2 Hangul Representations:
*
* - À¯´ÏÄÚµå 2.0 ÇÑ±Û ¿µ¿ª: 0xac00 ~ 0xd7a3 (11172ÀÚ)
* - À¯´ÏÄÚµå 1.1ÀÇ KSC5601 ´ëÀÀ ÇÑ±Û ¿µ¿ª: 0x3400 ~ 0x3d2d (2350ÀÚ) (Unicode 1.0)
* - À¯´ÏÄÚµå 1.1ÀÇ ÇÑ±Û º¸Ãæ ¿µ¿ª A, B: 0x3d2e ~ 0x4dff (4306ÀÚ) (Unicode 1.1, 1.2)
* (Âü°í: DB.java´Â ÀÌ ¿µ¿ªÀ» Áö¿øÇÏÁö ¾Ê´Â´Ù.)
* - KSC5601 ÇÑ±Û ¿µ¿ª: 0xb0a1 ~ 0xc8fe (2350ÀÚ)
*
* Author: Deogtae Kim, 98/02/05
*
*/
import java.sql.*;
class DB
{
// For verfication of this package.
public static void main( String[] args )
{
// For conversion between Unicode 2.0 and 1.2
if ( ! toUni12( "\uac00" ).equals( "\u3400" ) ||
! toUni12( "\ud79d" ).equals( "\u3d2d" ) ||
! fromUni12( "\u3400" ).equals( "\uac00" ) ||
! fromUni12( "\u3d2d" ).equals( "\ud79d" ) )
{
System.out.println( "Conversions between Unicode 1.2 and 2.0 failed." );
return;
}
System.out.println( "Conversions between Unicode 1.2 and 2.0 are O.K." );
}
// Unicode 2.0 -> Unicode 1.2
public static String toUni12( String uni20 )
{
int len = uni20.length();
char[] out = new char[len];
for( int i = 0; i < len; i++ )
{
char c = uni20.charAt(i);
if ( c < 0xac00 && 0xd7a3 < c )
{
out[i] = c;
} else // À¯´ÏÄÚµå 2.0 ÇÑ±Û ¿µ¿ª
{
try
{
byte[] ksc = String.valueOf(c).getBytes("KSC5601");
if ( ksc.length != 2 )
{
out[i] = '\ufffd';
System.err.println( "Warning: Some of Unicode 2.0 hangul character was ignored." );
} else
{
out[i] = (char) ( 0x3400 +
((ksc[0] & 0xff) - 0xb0) * 94 +
(ksc[1] & 0xff) - 0xa1 );
}
} catch( java.io.UnsupportedEncodingException ex )
{ throw new InternalError( "Fatal Error: KSC5601 encoding is not supported." );
}
}
}
return new String( out );
}
// Unicode 1.2 -> Unicode 2.0
public static String fromUni12( String uni12 )
{
int len = uni12.length();
char[] out = new char[len];
byte[] ksc = new byte[2];
for( int i = 0; i < len; i++ )
{
char c = uni12.charAt(i);
if ( c < 0x3400 && 0x4dff < c )
{
out[i] = c;
} else if ( 0x3d2e <= c ) // À¯´ÏÄÚµå 1.2 ÇÑ±Û º¸Ãæ ¿µ¿ª A, B
{
System.err.println( "Warning: Some of Unicode 1.2 hangul character was ignored." );
out[i] = '\ufffd';
} else // À¯´ÏÄÚµå 1.2ÀÇ KSC5601 ´ëÀÀ ÇÑ±Û ¿µ¿ª
{
try
{
ksc[0] = (byte) ( (c - 0x3400) / 94 + 0xb0 );
ksc[1] = (byte) ( (c - 0x3400) % 94 + 0xa1 );
out[i] = new String( ksc, "KSC5601" ).charAt(0);
} catch( java.io.UnsupportedEncodingException ex )
{ throw new InternalError( "Fatal Error: KSC5601 encoding is not supported." );
}
}
}
return new String( out );
}
}