본문 바로가기

IT/Java

MySQL 과 연동 하기

MySQL 에서 다운 받은 bin 파일을 


jre - bin 파일 아래에 넣어준다. 


프로젝트에서 우클릭 -  properties - Java Build Path - Libraries 탭 - Modulepath -옆 Add External JARs..클릭;


그리고 밑에 생성





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.sql.*;
 
public class Conntest {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 
        try { 
            //DB연결구문 
            Class.forName("com.mysql.jdbc.Driver");
            
            Connection conn = DriverManager.getConnection("jdbc:mysql://Localhost:3306/sample""root""0000");
                                    
            System.out.println("OK, Connection");
                
            conn.close();
            
        
        } catch(ClassNotFoundException ce) {
            System.out.println("DB Driver Error");
        } catch(SQLException e) {
            System.out.println("SQL 실패");
        }
    }
 
}
 
cs




'IT > Java' 카테고리의 다른 글

자바에서 mysql 연습 2  (0) 2018.05.24
자바에서 mysql 연습1  (0) 2018.05.21
자바연습-3-버블게임  (0) 2018.05.11
자바 연습-2- 슬롯머신  (0) 2018.05.10
자바 연습-1-영화표 예매  (0) 2018.05.10