테스트 환경
OS : Windows 10 64bit
Spring : 4.1.7.RELEASE
Java : 1.8
1. Maven의 pom.xml에 mysql 커넥터 추가
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
<scope>test</scope>
</dependency>
2. pom.xml에 junit 추가
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
3. src/test/java 아래에 테스트 클래스 생성 후 코드 작성
package org.zerock.web;
import java.sql.Connection;
import java.sql.DriverManager;
import org.junit.Test;
public class MySQLConnectionTest {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://xxx.xxx.xxx.xxx:3306/testDB";
private static final String USER ="test";
private static final String PW = "testpass";
@Test
public void testConnection() throws Exception{
Class.forName(DRIVER);
try (Connection con = DriverManager.getConnection(URL, USER, PW)) {
System.out.println(con);
}catch(Exception e){
System.err.println(e);
}
}
}
4. 결과출력
- 커넥션 객체 확인
com.mysql.jdbc.JDBC4Connection@19e1023e
참조 : 코드로 배우는 스프링 웹 프로젝트
'개발' 카테고리의 다른 글
[Spring] MyBatis 연동 (0) | 2017.12.15 |
---|---|
TCP/IP 통신 프로토콜 및 5계층화 (0) | 2017.11.23 |
[JAVA] 싱글톤 구현 예제 (0) | 2017.07.04 |
일반적인 디자인 패턴 종류 (0) | 2017.07.03 |
[MariaDB] ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. (0) | 2017.05.19 |