๐Ÿง๋งฅ๋ถ intelljIdea์™€ MysqlWorkbench ์—ฐ๋™ - ๋“œ๋ผ์ด๋ฒ„ ์„ค์ • ๋ฐฉ๋ฒ•(+ ์˜ค๋ฅ˜ ํ•ด๊ฒฐ)

์ดํ•˜์–€ยท2023๋…„ 8์›” 25์ผ
0

๐Ÿ’ก ํŒ

๋ชฉ๋ก ๋ณด๊ธฐ
4/7
post-thumbnail

  1. ๋“œ๋ผ์ด๋ฒ„ ๋‹ค์šด
    https://dev.mysql.com/downloads/connector/j/

  2. ์••์ถ• ํ•ด์ œ ๋ฐ ์ธํ…”๋ฆฌ์ œ์ด ์—ฐ๋™

  • ์••์ถ• ํ•ด์ œ

  • ์ธํ…”๋ฆฌ์ œ์ด์—์„œ ์„ค์ •๋ฐฉ๋ฒ•





    -> ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ์ •์ƒ์ ์œผ๋กœ ์ถ”๊ฐ€๋˜์—ˆ์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ์ฝ”๋“œ ์ž‘์„ฑ
    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) {}
    }

}
  • build.gradle
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()
}

-> ๋ชจ๋‘ ์™„๋ฃŒ ํ›„ ์‹คํ–‰

  • ๊ฒฐ๊ณผ
    java.lang.classnotfoundexception: com.mysql.jdbc.driver ์—๋Ÿฌ ๋ฐœ์ƒ
    -> ๋Œ€ํ‘œ์ ์ธ ์—ฐ๊ฒฐ ์˜ค๋ฅ˜๋กœ ๋‹ค์–‘ํ•œ ์ผ€์ด์Šค๊ฐ€ ์žˆ์–ด ํ˜„์žฌ ์ƒํ™ฉ์— ๋งž๊ฒŒ ์ด๊ฒƒ์ €๊ฒƒ ๊ฑด๋“œ๋ ค๋ณด๋Š”๊ฒŒ ๋‹ต!
  • ํ•ด๊ฒฐ
    ๋งฅ์—์„œ ํ„ฐ๋ฏธ๋„ ์‹คํ–‰ํ•˜์—ฌ Mysql์— ์‹ค์ œ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
    -> ํ™•์ธ ๊ฒฐ๊ณผ ์‹ค์ œ Mysql์—์„œ๋Š” ์ถ”๊ฐ€๊ฐ€ ์•ˆ๋˜์–ด ์žˆ์–ด ์ƒ์„ฑํ•ด์คŒ(์ด์ „ ์œˆ๋„์šฐ์—์„œ๋„ MysqlWorkbench ์‚ฌ์šฉ ์‹œ์— ๋™์ผํ•œ ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ์Œ)

  • ๋‹ค๋ฅธ ๋ฌธ์ œ

    -> ํ•ด๋‹น ๋ฌธ์ œ๋Š” ๊ธฐ์กด์˜ 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

profile
์–ธ์  ๊ฐ€ ๋‚ด ์ฝ”๋“œ๋กœ ์„ธ์ƒ์— ๊ธฐ์—ฌํ•  ์ˆ˜ ์žˆ๋„๋ก, BE&Data Science ๊ฐœ๋ฐœ ๊ธฐ๋ก ๋…ธํŠธโ˜˜๏ธ

0๊ฐœ์˜ ๋Œ“๊ธ€