Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


MySQL JDBC Connection
 
ÇÁ·Î±×·¡¹Ö¿¡ À־ µ¥ÀÌÅͺ£À̽º´Â ¾ø¾î¼­´Â ¾ÈµÉ µµ±¸ÀÌ´Ù. ÀÚ¹Ù´Â À¯¿¬ÇÑ JDBC¸¦ Á¦°øÇÑ´Ù. ÀÌ JDBC¸¦ ÅëÇؼ­ MySQLÀ» Á¢¼ÓÇÏ¿© µ¥ÀÌÅ͸¦ °¡Á®¿Àµµ·Ï ÇÏÀÚ ( 2003/02/28 ) 555
Written by ienvyou - ÃÖÁö¿õ
3 of 3
 
ÀÚ. ÀÌÁ¦ ÇÁ·Î±×·¥À» ÀÌ¿ëÇÏ¿© µ¥ÀÌÅÍ º£À̽º¿¡ Á¢¼Ó½ÃÄѺ¸µµ·Ï ÇÏÀÚ.

¸ÕÀú ÇÁ·Î±×·¥À» ¼öÇà½ÃÅ°±â Àü¿¡ classpath¿¡ MySQL Driver°¡ ÀÖ¾î¾ß µÇ´Â °Ç ´ç¿¬ÇÑ ¸»ÀÌ´Ù.

JDK_HOME/JRE/LIB/EXT/ ¿¡ ÇØ´ç µå¶óÀ̹ö mysql.jar¸¦ º¹»çÇϰųª
ȯ°æº¯¼ö¿¡ mysql.jarÆÄÀÏÀ» classpath¿¡ Ãß°¡½ÃŲÈÄ Å×½ºÆ®Çϵµ·Ï ÇÑ´Ù.

import java.sql.*;

public class MySQLJdbcTest {
   public static void main(String[] args) throws Exception{
      try{
        Class.forName("org.gjt.mm.mysql.Driver").newInstance();
        System.out.println("DriverLoading succeed..");

        String url="jdbc:mysql://127.0.0.1:3306/javabrain";
     //  ¸¸¾à À§ÀÇ url·Î Á¢¼Ó½Ã Çѱۿ¡ ¹®Á¦°¡ ¹ß»ýÇÏ¸é ¾Æ·¡ urlÀ» ½á¼­ »ç¿ëÇϵµ·Ï ÇÑ´Ù.
 
   //  String url="jdbc:mysql://127.0.0.1:3306/javabrain?useUnicode=true&characterEncoding=euc-kr";
        Connection conn =  DriverManager.getConnection(url,"scott","tiger");
        System.out.println("Connection succeed");
        Statement stmt = conn.createStatement();
        System.out.println("Á¤º¸ÃßÃâ");
  
        ResultSet rs = stmt.executeQuery("show databases");
       while( rs.next() ) {
         System.out.println(rs.getString(1));
       }
       System.out.println("MySQL ȯ°æ Á¡°Ë Á¾·á");
       rs.close();
       stmt.close();
       conn.close();
      }catch(Exception e){
         System.out.println(e);
      }
    }
}


 
1 2 3
References
 
http://www.mysql.com
http://java.sun.com/jdbc
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD