View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.jdbc.datasource;
17  
18  import java.sql.CallableStatement;
19  import java.sql.Connection;
20  
21  import javax.sql.DataSource;
22  
23  import org.kuali.common.jdbc.JdbcUtils;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  public class DriverManagerDataSourceTest {
28  
29  	private static final Logger logger = LoggerFactory.getLogger(DriverManagerDataSourceTest.class);
30  
31  	protected DataSource getMySQLDataSource(String url, String username, String password) {
32  		DriverManagerDataSource dmsd = new DriverManagerDataSource();
33  		dmsd.setDriverClassName("com.mysql.jdbc.Driver");
34  		dmsd.setUrl(url);
35  		dmsd.setUsername(username);
36  		dmsd.setPassword(password);
37  		return dmsd;
38  	}
39  
40  	protected DataSource getOracleDataSource(String url, String username, String password) {
41  		DriverManagerDataSource dmsd = new DriverManagerDataSource();
42  		dmsd.setDriverClassName("oracle.jdbc.driver.OracleDriver");
43  		dmsd.setUrl(url);
44  		dmsd.setUsername(username);
45  		dmsd.setPassword(password);
46  		return dmsd;
47  	}
48  
49  	// @Test
50  	public void testOracle() {
51  		try {
52  			DataSource dataSource = getOracleDataSource("jdbc:oracle:thin:@oracle.ks.kuali.org:1521:ORACLE", "master", "gw570229");
53  			Connection conn = DataSourceUtils.doGetConnection(dataSource);
54  			logger.info(conn + "");
55  			// String sql = "{ call rdsadmin.rdsadmin_util.restricted_session(false) }";
56  			// KSENV4 jeffcaddel administrators-MacBook-Pro-2.local JDBC Thin Client JDBC Thin Client 2013-01-03 15:04:24.0 667 34453
57  			String sql = "{ call rdsadmin.rdsadmin_util.kill(667,34457) }";
58  			String nativeSql = conn.nativeSQL(sql);
59  			logger.info("native sql=" + nativeSql);
60  			CallableStatement cstmt = conn.prepareCall(sql);
61  			// cstmt.setString(1, "667");
62  			// cstmt.setString(2, "34455");
63  			cstmt.execute();
64  			conn.commit();
65  			cstmt.close();
66  			JdbcUtils.closeQuietly(dataSource, conn);
67  		} catch (Exception e) {
68  			e.printStackTrace();
69  		}
70  
71  	}
72  
73  	// @Test
74  	public void test() {
75  		try {
76  			DataSource dataSource = getMySQLDataSource("jdbc:mysql://localhost", "root", null);
77  			Connection conn = DataSourceUtils.doGetConnection(dataSource);
78  			logger.info(conn + "");
79  			JdbcUtils.closeQuietly(dataSource, conn);
80  		} catch (Exception e) {
81  			e.printStackTrace();
82  		}
83  	}
84  
85  }