001 /**
002 * Copyright 2010-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.springframework.jdbc.datasource;
017
018 import java.sql.Connection;
019
020 import javax.sql.DataSource;
021
022 import org.junit.Test;
023 import org.kuali.common.jdbc.JdbcUtils;
024 import org.slf4j.Logger;
025 import org.slf4j.LoggerFactory;
026
027 public class DriverManagerDataSourceTest {
028
029 private static final Logger logger = LoggerFactory.getLogger(DriverManagerDataSourceTest.class);
030
031 protected DataSource getMySQLDataSource(String url, String username, String password) {
032 DriverManagerDataSource dmsd = new DriverManagerDataSource();
033 dmsd.setDriverClassName("com.mysql.jdbc.Driver");
034 dmsd.setUrl(url);
035 dmsd.setUsername(username);
036 dmsd.setPassword(password);
037 return dmsd;
038 }
039
040 @Test
041 public void test() {
042 try {
043 DataSource dataSource = getMySQLDataSource("jdbc:mysql://localhost", "root", null);
044 Connection conn = DataSourceUtils.doGetConnection(dataSource);
045 logger.info(conn + "");
046 JdbcUtils.closeQuietly(dataSource, conn);
047 } catch (Exception e) {
048 e.printStackTrace();
049 }
050
051 }
052
053 }