끄적끄적
[spring] database 연결 테스트 코드 본문
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();
}
}
}'개발' 카테고리의 다른 글
| [intelij] properties 파일 한글처리 (0) | 2020.01.06 |
|---|---|
| [spring] JPA properties 설정 (0) | 2019.12.26 |
| [spring] properties 여러개 사용하기 (0) | 2019.12.24 |
| [database] 자주 쓰는 SQL (0) | 2019.12.24 |
| [intelij] 인텔리제이 환경설정하기 (0) | 2019.12.24 |
Comments