티스토리 뷰

반응형

 

 

 

 

 

 

    ● build.gradle

 

//-- 추가
    implementation("mysql:mysql-connector-java:8.0.30")

 

 

    ● db 연결 테스트

        ○ myfirstspring / example / JDBCTestx.java

 

package com.myfirstspring.example;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCTests {
    @Test
    @DisplayName("db 연동 실습")
    public void testConnection() {

        //DB Driver Class
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        //URL
        Connection connection = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb",
                    "shop",
                    "My123456789!!s");
        } catch (SQLException e) {
            e.printStackTrace();
        }

        System.out.println(connection);

        try {
            connection.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}

 

 

 

 

 

 

 

 

 

 

'Back-End Programming > Spring' 카테고리의 다른 글

Mybatis 설정  (0) 2025.06.25
HikariCP 설정  (0) 2025.06.24
의존성 주입(DI)  (0) 2025.06.24
Log4j2 설정  (0) 2025.06.24
spring 5 설정  (0) 2025.06.24
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2026/02   »
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 28
글 보관함