๋๋ผ์ด๋ฒ ๋ค์ด
https://dev.mysql.com/downloads/connector/j/
์์ถ ํด์ ๋ฐ ์ธํ ๋ฆฌ์ ์ด ์ฐ๋
์์ถ ํด์
์ธํ
๋ฆฌ์ ์ด์์ ์ค์ ๋ฐฉ๋ฒ
-> ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ ์์ ์ผ๋ก ์ถ๊ฐ๋์์์ ํ์ธํ ์ ์๋ค.
์ฝ๋ ์์ฑ
Main.java
package org.example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
public static void main(String[] args) {
Connection con = null;
String server = "127.0.0.1"; // MySQL ์๋ฒ ์ฃผ์
String database = "dbtest"; // MySQL DATABASE ์ด๋ฆ
String user_name = "root"; // MySQL ์๋ฒ ์์ด๋
String password = ""; // MySQL ์๋ฒ ๋น๋ฐ๋ฒํธ
// 1.๋๋ผ์ด๋ฒ ๋ก๋ฉ
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.err.println(" !! <JDBC ์ค๋ฅ> Driver load ์ค๋ฅ: " + e.getMessage());
e.printStackTrace();
}
// 2.์ฐ๊ฒฐ
try {
con = DriverManager.getConnection("jdbc:mysql://" + server + "/" + database + "?useSSL=false", user_name, password);
System.out.println("์ ์์ ์ผ๋ก ์ฐ๊ฒฐ๋์์ต๋๋ค.");
} catch(SQLException e) {
System.err.println("con ์ค๋ฅ:" + e.getMessage());
e.printStackTrace();
}
// 3.ํด์
try {
if(con != null)
con.close();
} catch (SQLException e) {}
}
}
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'mysql:mysql-connector-java'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
-> ๋ชจ๋ ์๋ฃ ํ ์คํ
๋ค๋ฅธ ๋ฌธ์
-> ํด๋น ๋ฌธ์ ๋ ๊ธฐ์กด์ com.mysql.jdbc.Driver์์ com.mysql.cj.jdbc.Driver๋ก ๋ณ๊ฒฝํ๋ฉด ํด๊ฒฐ๋จ.
๋ณ๊ฒฝ ์ฌํญ
Main.java
...
// 1.๋๋ผ์ด๋ฒ ๋ก๋ฉ
try {
Class.forName("com.mysql.cj.jdbc.Driver"); //ํด๋น ๋ถ๋ถ ์์
} catch (ClassNotFoundException e) {
application.yml ์์ฑ
์ฐธ๊ณ ๋งํฌ
https://whitepaek.tistory.com/18
https://velog.io/@kms9887/mysql-%EB%8B%A4%EC%9A%B4%EB%A1%9C%EB%93%9C-workbench
https://developer-c.tistory.com/90
https://blog.naver.com/PostView.nhn?blogId=dldydldy&logNo=221536468135
https://atoz-develop.tistory.com/entry/IntelliJ%EB%A1%9C-Gradle-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8-%EC%83%9D%EC%84%B1%ED%95%98%EA%B3%A0-DB-%EC%97%B0%EB%8F%99%ED%95%98%EA%B8%B0
https://steady-benny.medium.com/how-to-handle-jdbc-exception-32be64e1d831
https://whitepaek.tistory.com/16
https://justdo-heal.tistory.com/41
https://wisdom-and-record.tistory.com/61
https://wakestand.tistory.com/695