1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
56
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
62
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
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 }