TIP/SPRING
mysql db연결 테스트
devjjin
2018. 10. 10. 19:52
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 | package kr.co.silver.board; import java.sql.Connection; import javax.inject.Inject; import javax.sql.DataSource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/**/root-context.xml" }) public class DataSourceTest { @Inject private DataSource ds; /** * @throws Exception */ @Test public void testConnection() throws Exception { try (Connection con = ds.getConnection()) { System.out.println(con); } catch (Exception e) { e.printStackTrace(); } } } | cs |