±Û¾´ÀÌ :±è´öÅ 1998³â 4¿ù 22ÀÏ 17:01:33
ConversionConnection.java´Â JDBC ÅëÇÕ ÇÑ±Û ÇØ°áÃ¥À» ¸ñÀûÀ¸·Î ¸¸µç
°ÍÀÔ´Ï´Ù.
JDBC µå¶óÀ̹ö ¹× DBMS ¸¶´Ù ÇѱÛÀ» »ç¿ëÇϱâ À§ÇÑ ¹æ½ÄÀÌ ¼·Î
´Ù¸£¹Ç·Î, ÅëÇÕµÇ°í °£ÆíÇÑ ¹æ¹ýÀ¸·Î ÇѱÛÀ» »ç¿ëÇϱâ À§Çؼ´Â
ConversionConnection.java¸¦ ÀÌ¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.
( http://calab.kaist.ac.kr/~dtkim/java/example/jdbc/ConversionConnection.java )
»ç¿ë¹æ¹ýÀº ´ÙÀ½°ú °°½À´Ï´Ù.
java.util.Properties props = new java.util.Properties();
props.put("charSet", "KSC5601" ); // µ¥ÀÌŸº£À̽º ÀÎÄÚµù ÁöÁ¤
// µå¶óÀ̹ö ȤÀº DBMS¿¡ µû¶ó¼´Â ÀÌ·¯ÇÑ ÁöÁ¤ÀÌ ÇÊ¿ä¾ø°Å³ª,
// ÁöÁ¤ÇÏÁö ¾Ê´Â °ÍÀÌ ´õ ÀûÀýÇÑ °æ¿ì°¡ ÀÖ´Ù.
// µå¶óÀ̹ö ȤÀº DBMS¿¡ µû¶ó¼´Â "KSC5601" ´ë½Å¿¡
// "UTF8"µî ´Ù¾çÇÑ ÀÎÄÚµùÀ» ÁöÁ¤ÇÒ ¼öµµ ÀÖ´Ù.
// Connection con = DriverManager.getConnection( db_url, props );
// ÇÑ±Û Ã³¸® (´Ù±¹¾î ó¸® Æ÷ÇÔ)¸¦ À§ÇØ ´ë½Å ´ÙÀ½°ú °°ÀÌ ÇÑ´Ù.
Connection con = ConversionConnection.getConnection( db_url, props );
// ³ª¸ÓÁö ºÎºÐÀº ¿µ¹® ó¸®ÇÏ´Â °æ¿ì¿Í µ¿ÀÏÇÏ´Ù.
ConversionConnection.javaÀ¸·Î ÇѱÛÀÌ ÇØ°áµÇÁö ¾Ê´Â °æ¿ì¿¡´Â ¼Ò½º
Äڵ带 º¸¸é ¿©·¯°¡Áö ÇØ°á ¹æ¹ýµéÀÌ µé¾î ÀÖÀ¸¸ç, ±× ¹üÁÖ¿¡ ¼ÓÇÒ
°ÍÀ̹ǷΠÀûÀýÈ÷ ¼öÁ¤ÇÏ¿© »ç¿ëÇÏ¸é µË´Ï´Ù.
Execute.java´Â »ç¿ë ¿¹Á¦ÀÔ´Ï´Ù.
( http://calab.kaist.ac.kr/~dtkim/java/example/jdbc/Execute.java )
´ÙÀ½Àº ÀÌÇظ¦ µ½±âÀ§Çؼ ConversionConnection.javaÀÇ ¾ÕºÎºÐ¸¸À» ¶¼¾î³½ °ÍÀÔ´Ï´Ù.
/*
* @(#)ConversionConnection.java 1.3 98/03/10
*
* Program Type: Package
*
* Purposes:
* 1. JDBC ¸í¼¼ ¹× µå¶óÀ̹öµéÀÇ ´Ù±¹¾î ¹× ÇÑ±Û Áö¿ø ºÎÁ·¿¡ ´ëóÇÑ´Ù.
* 2. JDBC µå¶óÀ̹öµéÀÇ ÀÎÄÚµù (¹®ÀÚ ÁýÇÕ) ó¸®ÀÇ ´Ù¾ç¼ºÀ» º¸¿ÏÇÔÀ¸·Î½á,
* ÇÑ±Û ¹× ´Ù¾çÇÑ ¾ð¾î ȯ°æÇÏ¿¡¼µµ µ¥ÀÌŸº£À̽º µ¶¸³¼ºÀ» ¾ò´Â´Ù.
* 3. µå¶óÀ̹öÀÇ ¹ö±×¸¦ º¸Á¤ÇÑ´Ù.
*
* ½ÇÇà ȯ°æ:
* ÀÚ¹Ù 1.1 ÀÌ»ó
*
* What to do:
* InstantDB, mSQL, Postgres, Oracle, FastForward, jConnectÀÌ¿Ü¿¡
* ÇÑ±Û »ç¿ë¿¡ ¹®Á¦°¡ ÀÖ´Â µå¶óÀ̹öµéÀ» º¸Á¤ÇÒ ¼ö ÀÖµµ·Ï È®Àå.
*
* Author: Deogtae Kim, 98/03/10
*/
import java.sql.*;
import java.io.*;
/**
* Abstract Code Conversion Class
*/
abstract class ConversionConnection implements Connection
{
public static Connection getConnection( String dbUrl, java.util.Properties props )
throws SQLException
{
Driver driver = DriverManager.getDriver(dbUrl);
String driverClass = driver.getClass().getName();
String charSet = props.getProperty( "charSet" );
if ( driverClass.equals( "jdbc.idbDriver" ) )
{ // InstantDB ¹× ³»Àå µå¶óÀ̹ö
// : À¯´ÏÄÚµå·Î ÀúÀåµÇ¹Ç·Î, charSetµîÀÇ ¼³Á¤ÀÌ ¾ø¾îµµ
// : ÇÑ±Û ¹× ´Ù±¹¾î¸¦ Á¦´ë·Î ó¸®ÇÑ´Ù.
} else if ( driverClass.equals( "com.sybase.jdbc.SybDriver" ) )
{ // Sybase¿ë jConnect µå¶óÀ̹ö 3.0
// : ´ÙÀ½°ú °°ÀÌ JCONNECT_VERSION ÇÁ·ÎÆÛƼ¸¦ ¼³Á¤ÇÑ ÈÄ¿¡´Â,
// charSet ÇÁ·ÎÆÛƼ¸¦ ¼³Á¤Çϸé ÁöÁ¤µÈ ÀÎÄÚµùÀ¸·Î º¯È¯ÇÏ°í,
// ¼³Á¤ÇÏÁö ¾ÊÀ¸¸é µ¥ÀÌŸº£À̽ºÀÇ µðÆúÆ® ÀÎÄÚµùÀ¸·Î º¯È¯ÇÑ´Ù.
// ´ÙÀ½Àº ÀÌ¿Í °°Àº ¼³Á¤ ¹× Àڹ٠ǥÁØ°ú ¹®ÀÚ ÀÎÄÚµù À̸§À»
// ´Þ¸®ÇϹǷΠÀ̸¦ º¸Á¤ÇÑ´Ù.
props.put( "JCONNECT_VERSION", "3" );
if ( charSet != null && charSet.equals( "KSC5601" ) )
props.put( "charSet", "eucksc" );
else if ( charSet != null )
props.put( "charSet", props.getProperty( charSet.toLowerCase() ) );
} else if ( driverClass.equals("sun.jdbc.odbc.JdbcOdbcDriver")
&& System.getProperty("java.version").compareTo( "1.2" ) >= 0 )
{ // JDK 1.2¿¡ ³»ÀåµÈ JDBC-ODBC ºê¸®Áö
// : "charSet" ÇÁ·ÎÆÛƼ·Î º¯È¯µÉ µ¥ÀÌŸº£À̽º ÀÎÄÚµùÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
} else if ( driverClass.equals( "com.imaginary.sql.msql.MsqlDriver" ) )
{ // mSQL JDBC µå¶óÀ̹ö 1.0b3
// : µðÆúÆ®·Î 8859_1 ÀÎÄÚµùÀ¸·Î º¯È¯ÇÏ¿© ÀúÀåÇÑ´Ù.
// : "encoding" ÇÁ·ÎÆÛƼ·Î µ¥ÀÌŸº£À̽º ÀÎÄÚµùÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
// ´ÙÀ½Àº "encoding" ÇÁ·ÎÆÛƼ ´ë½Å "charSet" ÇÁ·ÎÆÛƼ¸¦ »ç¿ëÇÒ ¼ö ÀÖ°Ô ÇÑ´Ù.
if ( charSet != null )
props.put( "encoding", props.getProperty( "charSet" ) );
} else if ( driverClass.equals( "weblogic.jdbc.dblib" ) )
{ // Sybase, Microsoft SQL Server¿ë WebLogic jdbcKona µå¶óÀ̹ö 3.01 (À¯Çü 2)
// : µðÆúÆ®·Î, 8859_1 ÀÎÄÚµùÀ¸·Î º¯È¯ÇÏ´Â °ÍÀ¸·Î ÃßÃøµÊ.
// : "weblogic.codeset" ÇÁ·ÎÆÛƼ·Î µ¥ÀÌŸº£À̽º ÀÎÄÚµùÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
if ( charSet != null )
props.put( "weblogic.codeset", props.getProperty( "charSet" ) );
} else if ( driverClass.equals( "connect.sybase.SybaseDriver" ) )
{ // Sybase SQL ¼¹ö¿ë FastForward µå¶óÀ̹ö 3.0
// : µ¥ÀÌŸº£À̽º µðÆúÆ® ÀÎÄÚµùÀ¸·Î ¹Ù¸£°Ô º¯È¯ÇÏ¿© ÀúÀåµÇ´Â °ÍÀ¸·Î ÃßÃøµÊ.
// : charSet ÇÁ·ÎÆÛƼ¸¦ Áö¿øÇÏÁö ¾Ê´Â °ÍÀ¸·Î ÃßÃøµÊ.
} else if ( driverClass.equals("oracle.jdbc.driver.OracleDriver") )
{ // ¿À¶óŬ Thin µå¶óÀ̹ö ȤÀº OCI7 µå¶óÀ̹ö 7.3.4
// : µ¥ÀÌŸº£À̽ºÀÇ µðÆúÆ® ÀÎÄÚµù°ú º¯È¯ÇÑ´Ù.
// : charSet ÇÁ·ÎÆÛƼ¸¦ Áö¿øÇÏÁö ¾Ê´Â´Ù.
// : - µ¥ÀÌŸº£À̽ºÀÇ µðÆúÆ® ÀÎÄÚµùÀÌ KSC5601ÀÎ °æ¿ì (º¸ÅëÀÇ °æ¿ì):
// : (Áï, NLS_DATABASE_PARAMETERS Å×À̺íÀÇ "NLS_CHARACTERSET" ¿ÀÇ °ªÀÌ
// : "KO16KSC5601"ÀÎ °æ¿ì¿¡ ÇØ´ç)
// : ÇÑ±Û Ç¥ÇöÀÌ ÀÚ¹ÙÀÇ À¯´ÏÄÚµå 2.0¿Í ´Ù¸¥ 1.2¸¦ »ç¿ëÇϹǷΠÀ̸¦ º¸Á¤ÇÑ´Ù.
// : ±×·¯³ª, ¿À¶óŬ µå¶óÀ̹öÀÇ ¹ö±×·Î ÀÎÇØ, CHAR, VARCHAR ÀÚ·áÇüÀÇ Å©±â¸¦
// : 50% Áõ°¡½ÃÄÑ¾ß Çϸç, µå¶óÀ̹öÀÇ ¹ö±×·Î ÀÎÇØ PreparedStatement°¡
// : ¿Àµ¿ÀÛÇÑ´Ù.
return new OracleConversionConnection( DriverManager.getConnection( dbUrl, props ) );
// : - µ¥ÀÌŸº£À̽ºÀÇ µðÆúÆ® ÀÎÄÚµùÀ» 8859_1·Î º¯°æÇÑ °æ¿ì:
// : (Áï, NLS_DATABASE_PARAMETERS Å×À̺íÀÇ "NLS_CHARACTERSET" ¿ÀÇ °ªÀÌ
// : "WE8ISO8859P1"ÀÎ °æ¿ì¿¡ ÇØ´ç)
// : ¾ÕÀÇ KSC5601À» return¹®À» »èÁ¦ÇÏ°í, ´ÙÀ½ return¹®ÀÇ ÄÚ¸àÆ®¸¦ Á¦°ÅÇÑ´Ù.
// : ÀÌ¿Í °°ÀÌ Çϸé, ÀÌ»óÀÇ ¹®Á¦°¡ ¹ß»ýÇÏÁö´Â ¾Ê´Â´Ù.
// : ´ÙÀ½Àº µ¥ÀÌŸº£À̽º ÀÎÄÚµù º¯°æÀ¸·Î ÀÎÇØ ÇѱÛÀ» »ç¿ëÇÒ ¼ö ÀÖµµ·Ï
// : ÄÚµå º¯È¯À¸·Î º¸Á¤ÇÑ´Ù.
/*
return new GeneralConversionConnection(
DriverManager.getConnection( dbUrl, props ),
(charSet == null) ? "KSC5601" : charSet, "8859_1" );
*/
} else if ( driverClass.equals( "connect.microsoft.MicrosoftDriver" ) )
{ // MS SQL ¼¹ö¿ë FastForward µå¶óÀ̹ö 3.0
// : ¹«Á¶°Ç 8859_1·Î º¯È¯ÇÏ´Â °ÍÀ¸·Î ÃßÃøµÊ.
if ( charSet != null && ! charSet.equals("8859_1") )
return new GeneralConversionConnection(
DriverManager.getConnection( dbUrl, props ), charSet, "8859_1" );
} else if ( driverClass.equals( "weblogic.jdbc.ifmx" ) )
{ // Informix¿ë webLogic jdbcKona µå¶óÀ̹ö (À¯Çü 2)
System.err.println( "Warning: Not yet verified. 8859_1 conversion is taken." );
if ( charSet != null && ! charSet.equals("8859_1") )
return new GeneralConversionConnection(
DriverManager.getConnection( dbUrl, props ), charSet, "8859_1" );
} else if ( driverClass.equals( "weblogic.jdbc.oci" ) )
{ // Oracle¿ë webLogic jdbcKona µå¶óÀ̹ö (À¯Çü 2)
// : µðÆúÆ®·Î, 8859_1 ÀÎÄÚµùÀ¸·Î º¯È¯ÇÑ´Ù.
// : "weblogic.oci.useUTF8" ¿¬°á ÇÁ·ÎÆÛƼ ¹×
// : "NLS_LANG" ȯ°æ º¯¼ö¿¡ ÀÇÇØ ÄÚµå º¯È¯ÀÌ ¿µÇâ¹Þ´Â´Ù.
// ´ÙÀ½Àº 8859_1 ÀÎÄÚµùÀ¸·Î º¯È¯ÇÏ°Ô ÇÏ°í, ÄÚµå º¯È¯À» º¸Á¤ÇÑ´Ù.
if ( charSet != null && ! charSet.equals("8859_1") )
return new GeneralConversionConnection(
DriverManager.getConnection( dbUrl, props ), charSet, "8859_1" );
} else if ( driverClass.equals( "openlink.jdbc.Driver" ) )
{ // OpenLink µå¶óÀ̹ö 3.0
// : ¹«Á¶°Ç 8859_1·Î º¯È¯ÇÏ´Â °ÍÀ¸·Î ÃßÃøµÊ. (È®ÀÎ ÇÊ¿ä)
System.err.println( "Warning: Not yet verified. 8859_1 conversion is taken." );
if ( charSet != null && ! charSet.equals("8859_1") )
return new GeneralConversionConnection(
DriverManager.getConnection( dbUrl, props ), charSet, "8859_1" );
} else if ( driverClass.equals( "weblogic.jdbc.t3.Driver" ) )
{ // WebLogic Tengah JDBC µå¶óÀ̹ö
// Tengah ¼¹öÃø¿¡ ¼³Ä¡µÇ´Â JDBC µå¶óÀ̹ö¿¡ ÇÑ±Û Ã³¸®°¡ ÇÊ¿äÇÏ´Ù.
} else if ( driverClass.equals( "postgresql.Driver" ) )
{ // Postgres ¹× ³»Àå µå¶óÀ̹ö
// : Ŭ¶óÀ̾ðÆ® µðÆúÆ® ÀÎÄÚµù¿¡ ÀÇÇØ °áÁ¤µÈ´Ù.
String clientEncoding = new java.io.OutputStreamWriter(System.out).getEncoding();
if ( props.getProperty( "charSet" ) != null
&& ! props.getProperty( "charSet" ).equals(clientEncoding) )
throw new SQLException( "client encoding and charSet value should be"
+ " the same in this driver" );
} else if ( driverClass.equals("sun.jdbc.odbc.JdbcOdbcDriver") )
{ // JDK 1.1 ³»Àå JDBC-ODBC ºê¸®Áö
// : Ŭ¶óÀ̾ðÆ® µðÆúÆ® ÀÎÄÚµù¿¡ ÀÇÇØ °áÁ¤µÇ´Â °ÍÀ¸·Î ÃßÃøµÊ.
System.err.println( "Warning: Not yet verified. No action is taken." );
} else
{
// ±âŸ µå¶óÀ̹öµé
System.err.println( "Warning: Not yet verified. No action is taken." );
}
return DriverManager.getConnection( dbUrl, props );
}
.......
--
Deogtae Kim (±è´öÅÂ)
CA Lab. CS Dept. KAIST
http://calab.kaist.ac.kr/~dtkim/java