-
Notifications
You must be signed in to change notification settings - Fork 8.5k
/
MySqlUtilsTest.java
33 lines (29 loc) · 1.27 KB
/
MySqlUtilsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.alibaba.druid.bvt.utils;
import com.alibaba.druid.util.MySqlUtils;
import com.mysql.jdbc.Driver;
import junit.framework.TestCase;
import java.lang.reflect.Constructor;
import java.sql.Connection;
public class MySqlUtilsTest extends TestCase {
public void test_xa() throws Exception {
Driver driver = new Driver();
int majorVersion = driver.getMajorVersion();
if (majorVersion == 5) {
Class<?> clazz_ConnectionImpl = Class.forName("com.mysql.jdbc.ConnectionImpl");
Constructor<?> constructor = clazz_ConnectionImpl.getDeclaredConstructor();
constructor.setAccessible(true);
Connection conn = (Connection) constructor.newInstance();
MySqlUtils.createXAConnection(driver, conn);
} else if (majorVersion == 6) {
Class<?> clazz_ConnectionImpl = Class.forName("com.mysql.cj.jdbc.ConnectionImpl");
Constructor<?> constructor = clazz_ConnectionImpl.getDeclaredConstructor();
constructor.setAccessible(true);
Connection conn = (Connection) constructor.newInstance();
try {
MySqlUtils.createXAConnection(driver, conn);
} catch (NullPointerException ex) {
//skip
}
}
}
}