eclipase version : 2023.12 (4.30)
MySQL version : 8.0.41
MySQL-jar-file version : 8.4.0
jar파일 설치하는 곳
https://downloads.mysql.com/archives/c-j/
MySQL :: Download MySQL Connector/J (Archived Versions)
Please note that these are old versions. New releases will have recent bug fixes and features! To download the latest release of MySQL Connector/J, please visit MySQL Downloads. MySQL open source software is provided under the GPL License.
downloads.mysql.com
1. MySQL 버전이랑 동일한 버전 선택 후 "Platform Independent, ZIP Archive" 설치
2. eclipse 접속 후 오른쪽 상단에 테이블 이모티콘 클릭
3. Database Development 선택
4. 왼쪽 파일에 Database Connections 우클릭 후 New
5. MySQL 선택
6. jar 파일로 설치한 버전은 8.4.0이지만 호환되는 버전이 적기에 5.1 선택
7. 상단에 JAR List 들어가서 설치한 jar 파일 넣기
8. 연결한 DB 포트번호와 DB이름, 그리고 user 이름이랑 비밀번호 입력
9. Test Connection을 눌러서 연결되었는지 확인
10. 선택한 DB와 연결 성공 확인 & 빨간 글씨로 표시한 부분 클릭 시 쿼리창 나옴
11. 쿼리 실행 결과 확인
12 . 다시 본 프로젝트 JDBC 파일로 돌아와서 우클릭 -> Build Path -> Configure Build Path.. 클릭
13. Modulepath에 아까 설치한 jar 파일 넣기
14. 확인
15. Referenced Libraries에 생성 확인
16. 모듈 불러오기 & 설정 및 연결
public static void main(String[] args) {
// JDBC : Java DataBase Connectivity
// 모듈 불러오기
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Driver Loading Success");
} catch (ClassNotFoundException e) {
System.out.println("DB Driver를 찾을 수 없습니다.");
}
// Database 정보를 설정하고 connection object를 취득해줘야한다.
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:포트번호/DB명", "user명", "비밀번호");
System.out.println("MySQL Connection Success");
} catch (SQLException e) {
System.out.println("Database를 연결할 수 없습니다.");
}
}
17. sql 파일 Package Explorer에서 보는 방법 : 쿼리문 작성 -> 저장 -> 원하는 Project 선택 -> file name 기입
18. 생성 확인
'Database > JDBC' 카테고리의 다른 글
JDBC) IntelliJ(Spring Boot) + MySQL 연동 / CRUD TEST (0) | 2025.03.20 |
---|