本文整理汇总了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 );
}
示例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");
}
}
示例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());
}
示例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));
}
示例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);
}
}
示例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" );
}
示例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;
}
示例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);
}
示例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" );
}
示例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();
}
示例11: getDriver
import java.sql.DriverManager; //导入方法依赖的package包/类
private static Driver getDriver() throws SQLException
{
return DriverManager.getDriver("jdbc:cloudspanner://localhost");
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}