티스토리 뷰
반응형
● 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 |
댓글