728x90
SMALL
pom.xml에서
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>jdbctest3</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.31</version>
</dependency>
</dependencies>
</project>
처럼 dependency를 추가하였는데도 com.mysql 에서 mysql-connector.jar 파일을 못찾는 오류가 발생했다.
package org.example;
public class DriverLoadingTest {
public DriverLoadingTest() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("로딩 성공");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("로딩 실패");
}
}
public static void main(String[] args) {
new DriverLoadingTest();
}
}
에서 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 에러를 뱉어냄
먼저 intellij 환경이고, 초심자라면 2번을 확인해보고, 안된다면 1번을 시도하라.
- external libraries에 직접 추가
- 메이븐 연결
1. external libraries에 직접 추가
[jsp] MySQL 연동 오류(java.lang.ClassNotFoundException: com.mysql.jdbc.Driver)
2. 메이븐 연결
인텔리제이에서,
나의 경우는 sync 완료 후 dependency를 추가했을 때
우상단에 메이븐 아이콘이 떴다.
해당 아이콘을 눌러야 dependency에 추가된 artifact를 다운로드해 자동으로 external libraries에 추가해주는듯 하다.
728x90
LIST