Search in sources :

Example 1 with Driver

use of com.mysql.jdbc.Driver in project druid by alibaba.

the class DruidConnectionHolderTest method setUp.

protected void setUp() throws Exception {
    driver = new Driver();
    if (driver.getMajorVersion() == 5) {
        exceptionClass = Class.forName("com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException");
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setTestOnBorrow(false);
        dataSource.setInitialSize(1);
        dataSource.getProxyFilters().add(new FilterAdapter() {

            public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection) throws SQLException {
                throw createSyntaxException();
            }
        });
    }
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) Driver(com.mysql.jdbc.Driver) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy)

Example 2 with Driver

use of com.mysql.jdbc.Driver in project druid by alibaba.

the class MySqlUtilsTest method test_.

public void test_() 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) {
    }
}
Also used : Connection(java.sql.Connection) Driver(com.mysql.jdbc.Driver)

Example 3 with Driver

use of com.mysql.jdbc.Driver in project zoj by licheng.

the class DatabaseHelper method createConnection.

/**
	 * Gets a connection.
	 * @return a connection
	 * @throws Exception to JUnit
	 */
public static Connection createConnection() throws Exception {
    Properties properties = new Properties();
    properties.load(new FileInputStream(CONFIG_FILE));
    Driver driver = (Driver) Class.forName(properties.getProperty("driver")).newInstance();
    String url = properties.getProperty("url");
    return driver.connect(url, properties);
}
Also used : Driver(com.mysql.jdbc.Driver) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

Driver (com.mysql.jdbc.Driver)3 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)1 FilterChain (com.alibaba.druid.filter.FilterChain)1 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)1 FileInputStream (java.io.FileInputStream)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1