µ¥ÀÌŸº£À̽º ÇÑ±Û ¹®Á¦ ÇØ°áÃ¥ÀÇ ¹ö±× ±³Á¤.


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :±è´öÅ 1998³â 2¿ù 25ÀÏ 19:20:11

In Reply to: ÇØ°á, ´Ù¸¥ Áú¹®..... posted by ÀüÀÀ½Ä on 1998³â 2¿ù 25ÀÏ 15:07:53:

DB.java¿¡ 2±ºµ¥¿¡¼­ ¹ö±×°¡ ÀÖ¾ú±º¿ä.
´ÙÀ½Àº ¼öÁ¤µÈ È­ÀÏÀÔ´Ï´Ù.


Áú¹®ÇϽŠ¹®Á¦´Â ¿À¶óŬ JDBC µå¶óÀ̹öÀÇ ¹ö±×ÀÏ °¡´É¼ºÀÌ ³ôÀº
°ÍÀ¸·Î º¸ÀÔ´Ï´Ù.
¸¸¾à ¹ö±×¶ó¸é, UTF8¿¡¼­´Â ÇѱÛÀÌ 3¹ÙÀÌÆ®, À¯´ÏÄڵ忡¼­´Â 2¹ÙÀÌÆ®,
KSC5601¿¡¼­´Â 2 ¹ÙÀÌÆ®·Î Ç¥ÇöµÇ¹Ç·Î, Ȥ½Ã ÀÏÁ¤ ºñÀ²À̶õ °ÍÀÌ
¼ø¼öÇÑ KSC5601 Çѱ۸¸À¸·Î ÀÌ·ç¾îÁ³À» °æ¿ì 2:3ÀÇ ºñÀ²ÀÌ ¾Æ´ÑÁö¿ä?
Á÷Á¢ Å×½ºÆ®Çغ¸±âÀü¿¡´Â È®½ÇÈ÷ ¸»¾¸µå¸®±â°¡ ¾î·Æ±º¿ä.



/*
 * @(#)DB.java	1.1 98/02/25
 *
 * Program Type: Package
 *
 * Purposes: 
 *    3. À¯´ÏÄÚµå 2.0°ú À¯´ÏÄÚµå 1.1, 1.2¿ÍÀÇ ÇÑ±Û Ç¥Çö Â÷À̸¦ º¸¿ÏÇÑ´Ù.
 *       (¿À¶óŬ 7 JDBC µå¶óÀ̹öÀÇ °æ¿ì)
 *    4. KSC5601 ¹®ÀÚ¸¦ Áö¿øÇÏÁö ¾Ê°í 8859-1 ¹®ÀÚ¸¸À» Áö¿øÇÏ´Â JDBC µå¶óÀ̹ö¿¡¼­ 
 *       ÇѱÛÀÌ ÀúÀå, °Ë»öµÇ°Ô ÇÑ´Ù. (±âŸ ´Ù¼ö JDBC µå¶óÀ̹ö)
 *
 * 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/25
 */
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( "a\uac00" ).equals( "a\u3400" ) ||
             ! toUni12( "a\ud79d" ).equals( "a\u3d2d" ) ||
             ! fromUni12( "a\u3400" ).equals( "a\uac00" ) ||
             ! fromUni12( "a\u3d2d" ).equals( "a\ud79d" )) 
            System.out.println( "Conversions between Unicode 1.2 and 2.0 failed." );
        else
            System.out.println( "Conversions between Unicode 1.2 and 2.0 are O.K." );
        // For conversion between KSC5601 range and 8859-1 range in Unicode 2.0
        if ( ! to8859_1( "a\uac00" ).equals( "a\u00b0\u00a1" ) ||
             ! from8859_1( "a\u00b0\u00a1" ).equals( "a\uac00" ) )
            System.out.println( "Conversions between KSC5601 range and 8859-1 range"
                                + " in Unicode 2.0 failed." );
        else
            System.out.println( "Conversions between KSC5601 range and 8859-1 range"
                                + " in Unicode 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 );
    }
    // KSC5601 range in Unicode 2.0 -> 8859_1 range in Unicode 2.0
    public static String to8859_1( String ksc )
    {   
        try
        {
            return new String( ksc.getBytes("KSC5601"), "8859_1" );
        } catch( java.io.UnsupportedEncodingException ex )
        {   throw new InternalError(
                "Fatal Error: KSC5601 or 8859_1 encoding is not supported." );
        }
    }
    // 8859_1 range in Unicode 2.0 -> KSC5601 range in Unicode 2.0
    public static String from8859_1( String iso8859_1 )
    {
        try
        {
            return new String( iso8859_1.getBytes("8859_1"), "KSC5601" );
        } catch( java.io.UnsupportedEncodingException ex )
        {   throw new InternalError(
                "Fatal Error: KSC5601 or 8859_1 encoding is not supported." );
        }
    }
}



´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]