1 package org.springframework.jdbc.datasource; 2 3 import java.sql.Connection; 4 5 import javax.sql.DataSource; 6 7 import org.junit.Test; 8 import org.kuali.common.jdbc.JdbcUtils; 9 import org.slf4j.Logger; 10 import org.slf4j.LoggerFactory; 11 12 public class DriverManagerDataSourceTest { 13 14 private static final Logger logger = LoggerFactory.getLogger(DriverManagerDataSourceTest.class); 15 16 protected DataSource getMySQLDataSource(String url, String username, String password) { 17 DriverManagerDataSource dmsd = new DriverManagerDataSource(); 18 dmsd.setDriverClassName("com.mysql.jdbc.Driver"); 19 dmsd.setUrl(url); 20 dmsd.setUsername(username); 21 dmsd.setPassword(password); 22 return dmsd; 23 } 24 25 @Test 26 public void test() { 27 try { 28 DataSource dataSource = getMySQLDataSource("jdbc:mysql://localhost", "root", null); 29 Connection conn = DataSourceUtils.doGetConnection(dataSource); 30 logger.info(conn + ""); 31 JdbcUtils.closeQuietly(dataSource, conn); 32 } catch (Exception e) { 33 e.printStackTrace(); 34 } 35 36 } 37 38 }