| 11 | import static org.junit.Assert.*; |
| 12 | |
| 13 | public class DBConnectionTest2 { |
| 14 | @Test |
| 15 | public void jdbcConnectionTest() throws Exception { |
| 16 | // // 스키마의 이름(springbasic)이 다른 경우 알맞게 변경 |
| 17 | // String DB_URL = "jdbc:mysql://localhost:3306/springbasic?useUnicode=true&characterEncoding=utf8"; |
| 18 | // |
| 19 | // // DB의 userid와 pwd를 알맞게 변경 |
| 20 | // String DB_USER = "asdf"; |
| 21 | // String DB_PASSWORD = "1234"; |
| 22 | // String DB_DRIVER = "com.mysql.jdbc.Driver"; |
| 23 | // |
| 24 | // DriverManagerDataSource ds = new DriverManagerDataSource(); |
| 25 | // ds.setDriverClassName(DB_DRIVER); |
| 26 | // ds.setUrl(DB_URL); |
| 27 | // ds.setUsername(DB_USER); |
| 28 | // ds.setPassword(DB_PASSWORD); |
| 29 | |
| 30 | ApplicationContext ac = new GenericXmlApplicationContext("file:src/main/webapp/WEB-INF/spring/**/root-context.xml"); |
| 31 | DataSource ds = ac.getBean(DataSource.class); |
| 32 | |
| 33 | Connection conn = ds.getConnection(); // 데이터베이스의 연결을 얻는다. |
| 34 | |
| 35 | System.out.println("conn = " + conn); |
| 36 | assertTrue(conn!=null); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /* [root-context.xml] |
| 41 | <?xml version="1.0" encoding="UTF-8"?> |
nothing calls this directly
no outgoing calls
no test coverage detected