ÀÚ. ÀÌÁ¦ ÇÁ·Î±×·¥À» ÀÌ¿ëÇÏ¿© µ¥ÀÌÅÍ º£À̽º¿¡ Á¢¼Ó½ÃÄѺ¸µµ·Ï ÇÏÀÚ.
¸ÕÀú ÇÁ·Î±×·¥À» ¼öÇà½ÃÅ°±â Àü¿¡ 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);
}
}
}
|