001    package org.springframework.jdbc.datasource;
002    
003    import java.sql.Connection;
004    
005    import javax.sql.DataSource;
006    
007    import org.junit.Test;
008    import org.kuali.common.jdbc.JdbcUtils;
009    import org.slf4j.Logger;
010    import org.slf4j.LoggerFactory;
011    
012    public class DriverManagerDataSourceTest {
013    
014            private static final Logger logger = LoggerFactory.getLogger(DriverManagerDataSourceTest.class);
015    
016            protected DataSource getMySQLDataSource(String url, String username, String password) {
017                    DriverManagerDataSource dmsd = new DriverManagerDataSource();
018                    dmsd.setDriverClassName("com.mysql.jdbc.Driver");
019                    dmsd.setUrl(url);
020                    dmsd.setUsername(username);
021                    dmsd.setPassword(password);
022                    return dmsd;
023            }
024    
025            @Test
026            public void test() {
027                    try {
028                            DataSource dataSource = getMySQLDataSource("jdbc:mysql://localhost", "root", null);
029                            Connection conn = DataSourceUtils.doGetConnection(dataSource);
030                            logger.info(conn + "");
031                            JdbcUtils.closeQuietly(dataSource, conn);
032                    } catch (Exception e) {
033                            e.printStackTrace();
034                    }
035    
036            }
037    
038    }