Notice
Recent Posts
Recent Comments
Link
«   2025/12   »
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 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

끄적끄적

[spring] database 연결 테스트 코드 본문

개발

[spring] database 연결 테스트 코드

으아아아앜 2019. 12. 24. 13:16

MySQL 기준입니다.

# MySQL Configuration
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/DB이름?useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Seoul

spring.datasource.username=root
spring.datasource.password=1234
@SpringBootTest
class DatabaseTests {
    @Value("${spring.datasource.driver-class-name}")
    private String DRIVER;
    @Value("${spring.datasource.url}")
    private String URL;
    @Value("${spring.datasource.username}")
    private String USER;
    @Value("${spring.datasource.password}")
    private String PW;

    @Test
    void dbConnectionTest() throws ClassNotFoundException {

        System.out.println(USER);
        System.out.println(PW);
        Class.forName(DRIVER);
        try(Connection con = DriverManager.getConnection(URL, USER, PW)) {
            System.out.println(con);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
Comments