JDBC를 이용하여 MySQL 서버에 접속하기
import java.sql.*;

public class JdbcTest {
	public static void main(String [] args){
		Connection conn= null;
		
		try{
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn=DriverManager.getConnection("jdbc:mysql:/dbserver","user","password");
			if(!conn.isClosed())
				System.out.println("Successfully connected to "+ "MySQL server using TCP/IP...");
		}catch(Exception e){
			System.err.println("Exception : "+e.getMessage());
		} finally{
			try{
				if(conn!=null) conn.close();
			}catch(SQLException e){}
		}
	}

}
Posted by 김민우 julingks