List of usage examples for java.sql DriverManager registerDriver
public static void registerDriver(java.sql.Driver driver) throws SQLException
From source file:gsn.vsensor.TestStreamExporterVirtualSensor.java
public void tearDown() { config = null;//from ww w . ja va 2s . c o m try { DriverManager.registerDriver(new org.h2.Driver()); Connection connection = DriverManager.getConnection(url, user, passwd); connection.createStatement().execute("DROP TABLE IF EXISTS " + streamName); } catch (SQLException e) { e.printStackTrace(); } }
From source file:org.apache.ctakes.jdl.data.base.JdlConnection.java
/** * Attempts to establish a connection./* ww w . jav a2s .c om*/ * * @throws InstantiationException * exception * @throws IllegalAccessException * exception * @throws ClassNotFoundException * exception * @throws SQLException * exception */ private void openConnection() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { // Class.forName(driver); DriverManager.registerDriver((Driver) Class.forName(driver).newInstance()); connection = DriverManager.getConnection(url, user, password); }
From source file:com.bloidonia.vertx.mods.JdbcProcessor.java
private static boolean setupPool(String address, String driver, String url, String username, String password, int minPool, int maxPool, int acquire, String automaticTestTable, int idleConnectionTestPeriod, String preferredTestQuery, boolean testConnectionOnCheckin, boolean testConnectionOnCheckout) throws Exception { if (poolMap.get(address) == null) { synchronized (poolMap) { if (poolMap.get(address) == null) { DriverManager.registerDriver((Driver) Class.forName(driver).newInstance()); ComboPooledDataSource pool = new ComboPooledDataSource(); pool.setDriverClass(driver); pool.setJdbcUrl(url);/*from w w w . j a v a 2 s . co m*/ pool.setUser(username); pool.setPassword(password); pool.setMinPoolSize(minPool); pool.setMaxPoolSize(maxPool); pool.setAcquireIncrement(acquire); pool.setAutomaticTestTable(automaticTestTable); pool.setIdleConnectionTestPeriod(idleConnectionTestPeriod); pool.setPreferredTestQuery(preferredTestQuery); pool.setTestConnectionOnCheckin(testConnectionOnCheckin); pool.setTestConnectionOnCheckout(testConnectionOnCheckout); if (poolMap.putIfAbsent(address, pool) != null) { pool.close(); } else { metrics = new MetricRegistry(String.format("%s.metrics", address)); requests = metrics.meter(name(JdbcProcessor.class, "requests")); jmxReporter = JmxReporter.forRegistry(metrics).build(); jmxReporter.start(); return true; } } } } return false; }
From source file:org.pentaho.di.core.database.ConnectionPoolUtilTest.java
public ConnectionPoolUtilTest() { try {/*from w w w . j a v a2s.c o m*/ DriverManager.registerDriver(this); } catch (SQLException e) { e.printStackTrace(); } }
From source file:nz.co.senanque.schemabuilder.SchemaBuilderTask.java
private void registerDriver() { try {/*from www . j a v a 2 s .co m*/ Driver driver = (Driver) Class.forName(getDriver()).newInstance(); DriverManager.registerDriver(driver); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.espertech.esperio.db.SupportDatabaseService.java
/** * Strictly for use in regression testing, this method provides a connection via driver manager. * @param url url/*from w w w . j a va2s . c o m*/ * @param username user * @param password password * @return connection */ public static Connection getConnection(String url, String username, String password) { log.info("Creating new connection instance for pool for url " + url); Driver d; try { d = (Driver) Class.forName(DRIVER).newInstance(); DriverManager.registerDriver(d); } catch (Exception e) { String message = "Failed to load and register driver class:" + e.getMessage(); log.error(message, e); throw new RuntimeException(message, e); } Connection connection; try { connection = DriverManager.getConnection(url, username, password); } catch (SQLException e) { String message = "Failed to obtain a database connection using url '" + url + "' and user '" + username + "' :" + e.getMessage(); log.error(message, e); throw new RuntimeException(message, e); } try { connection.setAutoCommit(false); } catch (SQLException e) { String message = "Failed to set auto-commit on connection '" + url + "' and user '" + username + "' :" + e.getMessage(); log.error(message, e); throw new RuntimeException(message, e); } return connection; }
From source file:edu.education.ucsb.muster.MusterServlet.java
private String testConnectivity(DatabaseDefinition db) { // load driver try {//from www .jav a2 s .c o m DriverManager.getDriver(db.url); } catch (SQLException e) { try { DriverManager.registerDriver( (Driver) Class.forName(db.driver).getConstructor().newInstance((Object[]) null)); } catch (Exception e1) { addException(e1, "A driver couldn't be loaded. Check the config file and try again. driver: `" + db.driver + "`, confPath: `" + confPath + "`"); return "FAIL"; } } // connect and test setReadOnly // Add the connection to our list and try setting readOnly to test Connection connection = null; try { connection = DriverManager.getConnection(db.url, db.username, db.password); connection.setReadOnly(true); connection.close(); } catch (Exception e) { addException(e, "Setting readonly failed on " + db.url); return e.toString(); } return "OK"; }
From source file:org.wsm.database.tools.util.ConnectionManager.java
private static Driver loadDriver(final String dbType) throws DBConnectionFailedException { Driver temp = null;//w ww .ja v a2 s . c o m if (DbUtilConstants.DATABASE_TYPE_ORACLE.equals(dbType)) { try { temp = new oracle.jdbc.driver.OracleDriver(); DriverManager.registerDriver(temp); } catch (SQLException e) { throw new DBConnectionFailedException("Unable to register" + dbType + "Driver"); } } else if (DbUtilConstants.DATABASE_TYPE_MYSQL.equals(dbType)) { try { temp = new com.mysql.jdbc.Driver(); DriverManager.registerDriver(temp); } catch (SQLException e) { throw new DBConnectionFailedException("Unable to register" + dbType + "Driver"); } } return temp; }
From source file:org.pentaho.di.core.database.ConnectionPoolUtilIntegrationIT.java
@Before public void setUp() throws Exception { driver = mock(Driver.class, RETURNS_MOCKS); DriverManager.registerDriver(driver); logChannelInterface = mock(LogChannelInterface.class, RETURNS_MOCKS); dsProps = new Properties(); dsProps.setProperty(ConnectionPoolUtil.DEFAULT_AUTO_COMMIT, "true"); dsProps.setProperty(ConnectionPoolUtil.DEFAULT_READ_ONLY, "true"); dsProps.setProperty(ConnectionPoolUtil.DEFAULT_TRANSACTION_ISOLATION, "1"); dsProps.setProperty(ConnectionPoolUtil.DEFAULT_CATALOG, ""); dsProps.setProperty(ConnectionPoolUtil.MAX_IDLE, "30"); dsProps.setProperty(ConnectionPoolUtil.MIN_IDLE, "3"); dsProps.setProperty(ConnectionPoolUtil.MAX_WAIT, String.valueOf(MAX_WAIT_TIME)); // tested dsProps.setProperty(ConnectionPoolUtil.VALIDATION_QUERY, VALIDATION_QUERY); dsProps.setProperty(ConnectionPoolUtil.TEST_ON_BORROW, "true"); dsProps.setProperty(ConnectionPoolUtil.TEST_ON_RETURN, "true"); dsProps.setProperty(ConnectionPoolUtil.TEST_WHILE_IDLE, "true"); dsProps.setProperty(ConnectionPoolUtil.TIME_BETWEEN_EVICTION_RUNS_MILLIS, "300000"); dsProps.setProperty(ConnectionPoolUtil.POOL_PREPARED_STATEMENTS, "true"); // tested dsProps.setProperty(ConnectionPoolUtil.MAX_OPEN_PREPARED_STATEMENTS, "2"); // tested dsProps.setProperty(ConnectionPoolUtil.ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED, "true"); // tested dsProps.setProperty(ConnectionPoolUtil.REMOVE_ABANDONED, "false"); dsProps.setProperty(ConnectionPoolUtil.REMOVE_ABANDONED_TIMEOUT, "1000"); dsProps.setProperty(ConnectionPoolUtil.LOG_ABANDONED, "false"); }
From source file:com.pikai.jdbc.testcase.PoolTest.java
protected void setUp() throws Exception { DriverManager.registerDriver(TestDriver.instance); user = "root"; password = "123456"; // jdbcUrl = "jdbc:h2:mem:"; // driverClass = "org.h2.Driver"; jdbcUrl = "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&useOldAliasMetadataBehavior=true"; driverClass = "com.mysql.jdbc.Driver"; physicalConnStat.set(0);/* w w w.j av a2s . c o m*/ }