|
@@ -0,0 +1,47 @@
|
|
1
|
+import com.alibaba.druid.pool.DruidDataSource;
|
|
2
|
+import com.alibaba.druid.pool.DruidPooledConnection;
|
|
3
|
+import com.mchange.v2.c3p0.ComboPooledDataSource;
|
|
4
|
+import org.junit.Test;
|
|
5
|
+
|
|
6
|
+import java.sql.Connection;
|
|
7
|
+import java.util.ResourceBundle;
|
|
8
|
+
|
|
9
|
+/**
|
|
10
|
+ * 数据源测试
|
|
11
|
+ */
|
|
12
|
+public class DataSourceTest {
|
|
13
|
+ /**
|
|
14
|
+ * 测试c3p0数据源
|
|
15
|
+ * @throws Exception
|
|
16
|
+ */
|
|
17
|
+ @Test
|
|
18
|
+ public void c3p0Test() throws Exception{
|
|
19
|
+ ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
|
|
20
|
+ comboPooledDataSource.setDriverClass("com.mysql.jdbc.Driver");
|
|
21
|
+ comboPooledDataSource.setJdbcUrl("jdbc:mysql://47.110.156.18:3306/sczn_eshop_test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai");
|
|
22
|
+ comboPooledDataSource.setUser("sczn");
|
|
23
|
+ comboPooledDataSource.setPassword("sczn159357");
|
|
24
|
+ Connection connection = comboPooledDataSource.getConnection();
|
|
25
|
+ System.out.println(connection);
|
|
26
|
+ connection.close();
|
|
27
|
+ }
|
|
28
|
+ /**
|
|
29
|
+ * 测试 druid
|
|
30
|
+ */
|
|
31
|
+ @Test
|
|
32
|
+ public void druidTest() throws Exception {
|
|
33
|
+ ResourceBundle resourceBundle = ResourceBundle.getBundle("jdbc");
|
|
34
|
+ String driver = resourceBundle.getString("jdbc.driver");
|
|
35
|
+ String url = resourceBundle.getString("jdbc.url");
|
|
36
|
+ String username = resourceBundle.getString("jdbc.username");
|
|
37
|
+ String password = resourceBundle.getString("jdbc.password");
|
|
38
|
+ DruidDataSource druidDataSource = new DruidDataSource();
|
|
39
|
+ druidDataSource.setDriverClassName(driver);
|
|
40
|
+ druidDataSource.setUrl(url);
|
|
41
|
+ druidDataSource.setUsername(username);
|
|
42
|
+ druidDataSource.setPassword(password);
|
|
43
|
+ Connection connection = druidDataSource.getConnection();
|
|
44
|
+ System.out.println(connection);
|
|
45
|
+ connection.close();
|
|
46
|
+ }
|
|
47
|
+}
|