mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add mysql-driver 6.0.x support
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<!--
|
||||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
-->
|
||||
-->
|
||||
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.0.24-SNAPSHOT</version>
|
||||
@@ -473,7 +475,7 @@
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.38</version>
|
||||
<version>6.0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -45,6 +45,10 @@ public class MySqlValidConnectionChecker extends ValidConnectionCheckerAdapter i
|
||||
public MySqlValidConnectionChecker(){
|
||||
try {
|
||||
clazz = Utils.loadClass("com.mysql.jdbc.MySQLConnection");
|
||||
if (clazz == null) {
|
||||
clazz = Utils.loadClass("com.mysql.cj.jdbc.ConnectionImpl");
|
||||
}
|
||||
|
||||
if (clazz != null) {
|
||||
ping = clazz.getMethod("pingInternal", boolean.class, int.class);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.alibaba.druid.pool.mysql;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/8/5.
|
||||
@@ -13,12 +16,12 @@ public class MySqlTest extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mysql://a.b.c.e:3906/");
|
||||
dataSource.setUsername("a");
|
||||
dataSource.setPassword("b");
|
||||
dataSource.setUrl("jdbc:mysql://raspberrypi_mysql:3306/druid_test_db?allowMultiQueries=true");
|
||||
dataSource.setUsername("druid_test");
|
||||
dataSource.setPassword("druid_test");
|
||||
dataSource.setFilters("log4j");
|
||||
dataSource.setValidationQuery("SELECT 1");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setTestOnBorrow(true);
|
||||
dataSource.setTestWhileIdle(true);
|
||||
}
|
||||
|
||||
@@ -28,6 +31,25 @@ public class MySqlTest extends TestCase {
|
||||
|
||||
public void test_mysql() throws Exception {
|
||||
Connection connection = dataSource.getConnection();
|
||||
|
||||
System.out.println("----------- : " + connection.unwrap(Connection.class).getClass());
|
||||
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.execute("select 1;select 1");
|
||||
|
||||
ResultSet rs = stmt.getResultSet();
|
||||
Assert.assertFalse(rs.isClosed());
|
||||
|
||||
Assert.assertTrue(stmt.getMoreResults());
|
||||
Assert.assertTrue(rs.isClosed());
|
||||
|
||||
ResultSet rs2 = stmt.getResultSet();
|
||||
Assert.assertFalse(rs2.isClosed());
|
||||
rs2.close();
|
||||
Assert.assertTrue(rs2.isClosed());
|
||||
|
||||
stmt.close();
|
||||
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user