当前位置: 首页>>代码示例>>Java>>正文


Java DriverManager.getDriver方法代码示例

本文整理汇总了Java中java.sql.DriverManager.getDriver方法的典型用法代码示例。如果您正苦于以下问题:Java DriverManager.getDriver方法的具体用法?Java DriverManager.getDriver怎么用?Java DriverManager.getDriver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.DriverManager的用法示例。


在下文中一共展示了DriverManager.getDriver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ConnectionFactory

import java.sql.DriverManager; //导入方法依赖的package包/类
@SuppressWarnings( "unchecked" )
public ConnectionFactory(AgroalConnectionFactoryConfiguration configuration) {
    try {
        ClassLoader driverLoader = configuration.classLoaderProvider().getClassLoader( configuration.driverClassName() );
        Class<Driver> driverClass = (Class<Driver>) driverLoader.loadClass( configuration.driverClassName() );
        this.driver = driverClass.newInstance();
    } catch ( IllegalAccessException | InstantiationException | ClassNotFoundException e ) {
        try {
            // Fallback to load the Driver through the DriverManager
            this.driver = DriverManager.getDriver( configuration.jdbcUrl() );
        } catch ( SQLException ig ) {
            throw new RuntimeException( "Unable to load driver class", e );
        }
    }

    this.configuration = configuration;
    this.jdbcProperties = configuration.jdbcProperties();
    setupSecurity( configuration );
}
 
开发者ID:agroal,项目名称:agroal,代码行数:20,代码来源:ConnectionFactory.java

示例2: getDriver

import java.sql.DriverManager; //导入方法依赖的package包/类
private static Driver getDriver(JdbcSamplerBuilder builder){
    try {
        return DriverManager.getDriver(builder.getUrl());
    } catch (SQLException e) {
        throw new IllegalArgumentException("Unable to locate driver");
    }
}
 
开发者ID:gilles-stragier,项目名称:quickmon,代码行数:8,代码来源:JdbcSampler.java

示例3: test16

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Validate that DriverAction.release is called when a driver is registered
 * via registerDriver(Driver, DriverAction)
 *
 * @throws Exception
 */
@Test
public void test16() throws Exception {
    File file = new File(util.StubDriverDA.DriverActionCalled);
    file.delete();
    assertFalse(file.exists());
    Driver d = null;
    Class.forName("util.StubDriverDA");
    d = DriverManager.getDriver(StubDriverDAURL);
    DriverManager.deregisterDriver(d);
    assertFalse(isDriverRegistered(d), "Driver is registered");
    assertTrue(file.exists());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DriverManagerTests.java

示例4: test15

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Register a driver and make sure you find it via its URL. Deregister the
 * driver and validate it is not longer registered
 *
 * @throws Exception
 */
@Test()
public void test15() throws Exception {
    DriverManager.registerDriver(new StubDriver());
    Driver d = DriverManager.getDriver(StubDriverURL);
    assertTrue(d != null);
    assertTrue(isDriverRegistered(d));
    DriverManager.deregisterDriver(d);
    assertFalse(isDriverRegistered(d));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:DriverManagerTests.java

示例5: shutdownAllDriver

import java.sql.DriverManager; //导入方法依赖的package包/类
public static void shutdownAllDriver() {
	try {
		PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
		for (String poolName : driver.getPoolNames()) {
			driver.closePool(poolName);
			
			if (ConnInfoList.containsKey(poolName)) {
				ConnInfoList.remove(poolName);
			}	
		}
	}catch(Exception e){
		LogUtils.error(CommonUtil.getStackTrace(e), DBCPPoolManager.class);
	}
}
 
开发者ID:experdb,项目名称:eXperDB-DB2PG,代码行数:15,代码来源:DBCPPoolManager.java

示例6: setUpTestCase

import java.sql.DriverManager; //导入方法依赖的package包/类
@BeforeClass
public static void setUpTestCase() throws SQLException,
                                          ClassNotFoundException {
  Class.forName( "org.apache.drill.jdbc.proxy.TracingProxyDriver" );
  proxyDriver =
      DriverManager.getDriver(
          "jdbc:proxy:org.apache.drill.jdbc.Driver:jdbc:drill:zk=local" );
  proxyConnection =
      DriverManager.getConnection( "jdbc:proxy::jdbc:drill:zk=local" );
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:11,代码来源:TracingProxyDriverTest.java

示例7: getHikariConfig

import java.sql.DriverManager; //导入方法依赖的package包/类
protected HikariConfig getHikariConfig() throws SQLException {
  HikariConfig hikariConfig = new HikariConfig();

  String jdbcUrl = getJdbcUrl().orElseThrow(IllegalStateException::new);
  hikariConfig.setJdbcUrl(jdbcUrl);

  Driver jdbcDriver = DriverManager.getDriver(jdbcUrl);
  hikariConfig.setDriverClassName(jdbcDriver.getClass().getName());

  getJdbcUsername().ifPresent(hikariConfig::setUsername);
  getJdbcPassword().ifPresent(hikariConfig::setPassword);
  return hikariConfig;
}
 
开发者ID:springuni,项目名称:springuni-particles,代码行数:14,代码来源:AbstractJpaRepositoryConfiguration.java

示例8: prepare

import java.sql.DriverManager; //导入方法依赖的package包/类
public void prepare(String size) throws Exception {
  this.firstIteration = true;
  this.size = size;

  configure();

  // make the database relative to the scratch location
  if (inMemoryDB)
    database = DATABASE_NAME_MEMORY;
  else
    database = new File(new File(scratch, "db"), DATABASE_NAME_DISK).toURI().toString();

  // seem to need to set this early and in the system properties
  Class.forName(DRIVER_NAME);
  driver = DriverManager.getDriver(URL_BASE + database);

  properties = (Properties) System.getProperties().clone();

  properties.setProperty(USERNAME, USER);
  properties.setProperty(PASSWORD, PASS);

  // make a seeded random number generator for each submitter
  rands = new OERandom[numberOfTerminals];

  // create a set of Submitter each with a Standard operations implementation
  connections = new Connection[numberOfTerminals];
  submitters = new Submitter[numberOfTerminals];
  transactionsPerTerminal = new int[numberOfTerminals];

  // set up the transactions for each terminal
  final int iterationsPerClient = totalTransactions / numberOfTerminals;
  final int oddIterations = totalTransactions - (iterationsPerClient * numberOfTerminals);

  for (int i = 0; i < numberOfTerminals; i++)
    transactionsPerTerminal[i] = iterationsPerClient + (i < oddIterations ? 1 : 0);
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:37,代码来源:TPCC.java

示例9: setUpTestCase

import java.sql.DriverManager; //导入方法依赖的package包/类
@BeforeClass
public static void setUpTestCase() throws SQLException,
                                          ClassNotFoundException {
  Class.forName( "com.dremio.jdbc.proxy.TracingProxyDriver" );
  proxyDriver =
      DriverManager.getDriver(
          "jdbc:proxy:com.dremio.jdbc.Driver:jdbc:dremio:zk=local" );
  proxyConnection =
      DriverManager.getConnection( "jdbc:proxy::jdbc:dremio:zk=local" );
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:11,代码来源:TracingProxyDriverTest.java

示例10: test

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Validate JDBC drivers as modules will be accessible. One driver will be
 * loaded and registered via the service-provider loading mechanism. The
 * other driver will need to be explictly loaded
 *
 * @throws java.lang.Exception
 */
@Test
public void test() throws Exception {
    System.out.println("\n$$$ runing Test()\n");
    dumpRegisteredDrivers();
    Driver d = DriverManager.getDriver(STUBDRIVERURL);
    assertNotNull(d, "StubDriver should not be null");
    assertTrue(isDriverRegistered(d));
    Driver d2 = null;

    // This driver should not be found until it is explictly loaded
    try {
        d2 = DriverManager.getDriver(LUCKYDOGDRIVER_URL);
    } catch (SQLException e) {
        // ignore expected Exception
    }
    assertNull(d2, "LuckyDogDriver should  be null");
    loadDriver();
    d2 = DriverManager.getDriver(LUCKYDOGDRIVER_URL);
    assertNotNull(d2, "LuckyDogDriver should not be null");
    assertTrue(isDriverRegistered(d2), "Driver was NOT registered");

    dumpRegisteredDrivers();
    DriverManager.deregisterDriver(d2);
    assertFalse(isDriverRegistered(d2), "Driver IS STILL registered");
    dumpRegisteredDrivers();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:DriverManagerModuleTests.java

示例11: getDriver

import java.sql.DriverManager; //导入方法依赖的package包/类
private static Driver getDriver() throws SQLException
{
	return DriverManager.getDriver("jdbc:cloudspanner://localhost");
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:5,代码来源:CloudSpannerDriverTest.java

示例12: GetPoolNameList

import java.sql.DriverManager; //导入方法依赖的package包/类
public static String[] GetPoolNameList() throws Exception {
	PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
	return driver.getPoolNames();
}
 
开发者ID:experdb,项目名称:eXperDB-DB2PG,代码行数:5,代码来源:DBCPPoolManager.java

示例13: test11

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Validate that SQLException is thrown when null is passed for the URL
 */
@Test(expectedExceptions = SQLException.class)
public void test11() throws Exception {
    DriverManager.getDriver(null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:DriverManagerTests.java

示例14: test13

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Validate that SQLException is thrown when the URL is not valid for any of
 * the registered drivers
 */
@Test(expectedExceptions = SQLException.class)
public void test13() throws Exception {
    DriverManager.registerDriver(new StubDriver());
    DriverManager.getDriver(InvalidURL);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:DriverManagerTests.java

示例15: test10

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Validate that SQLException is thrown when there is no Driver to service
 * the URL
 */
@Test(expectedExceptions = SQLException.class)
public void test10() throws Exception {
    DriverManager.getDriver(InvalidURL);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:DriverManagerTests.java


注:本文中的java.sql.DriverManager.getDriver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。