Refine search
public static Connection getConnection(String url) throws SQLException { for (Driver driver : registeredDrivers) { if (driver.acceptsURL(url)) { return driver.connect(url); } } throw new SQLException("No suitable driver"); }
@Override public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { return driver.getPropertyInfo(url, info); }
protected void initCheck() throws SQLException { if (JdbcUtils.ORACLE.equals(this.dbType)) { isOracle = true; if (driver.getMajorVersion() < 10) { throw new SQLException("not support oracle driver " + driver.getMajorVersion() + "." + driver.getMinorVersion()); } if (driver.getMajorVersion() == 10 && isUseOracleImplicitCache()) { this.getConnectProperties().setProperty("oracle.jdbc.FreeMemoryOnEnterImplicitCache", "true"); } oracleValidationQueryCheck(); } else if (JdbcUtils.DB2.equals(dbType)) { db2ValidationQueryCheck(); } else if (JdbcUtils.MYSQL.equals(this.dbType) || JdbcUtils.MYSQL_DRIVER_6.equals(this.dbType)) { isMySql = true; } if (removeAbandoned) { LOG.warn("removeAbandoned is true, not use in productiion."); } }
private boolean check(String name, DruidDataSource dataSource) { boolean result = true; Driver driver = dataSource.getRawDriver(); Properties info = new Properties(dataSource.getConnectProperties()); String username = dataSource.getUsername(); String password = dataSource.getPassword(); String url = dataSource.getUrl(); // We can't use rawUrl here, because the schema maybe set in url. Connection conn = null; if (info.getProperty("user") == null && username != null) { info.setProperty("user", username); } if (info.getProperty("password") == null && password != null) { info.setProperty("password", password); } try { LOG.debug("Validating " + name + " every " + sleepSeconds + " seconds."); conn = driver.connect(url, info); dataSource.validateConnection(conn); } catch (SQLException e) { LOG.warn("Validation FAILED for " + name + " with url [" + url + "] and username [" + info.getProperty("user") + "]. Exception: " + e.getMessage()); result = false; } finally { JdbcUtils.close(conn); } return result; }
static Connection getConnection(Configuration conf) throws Exception { String jdbcDriver = MetastoreConf.getVar(conf, ConfVars.CONNECTION_DRIVER); Driver driver = (Driver) Class.forName(jdbcDriver).newInstance(); Properties prop = new Properties(); String driverUrl = MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY); String user = MetastoreConf.getVar(conf, ConfVars.CONNECTION_USER_NAME); String passwd = MetastoreConf.getPassword(conf, MetastoreConf.ConfVars.PWD); prop.setProperty("user", user); prop.setProperty("password", passwd); Connection conn = driver.connect(driverUrl, prop); conn.setAutoCommit(true); return conn; }
public DriverDataSource(String jdbcUrl, String driverClassName, Properties properties, String username, String password) this.driverProperties = new Properties(); for (Entry<Object, Object> entry : properties.entrySet()) { driverProperties.setProperty(entry.getKey().toString(), entry.getValue().toString()); Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver d = drivers.nextElement(); try { if (driver == null) { driver = DriverManager.getDriver(jdbcUrl); LOGGER.debug("Loaded driver with class name {} for jdbcUrl={}", driver.getClass().getName(), sanitizedUrl); else if (!driver.acceptsURL(jdbcUrl)) { throw new RuntimeException("Driver " + driverClassName + " claims to not accept jdbcUrl, " + sanitizedUrl);
if (beakerParser.getDbURI().getUser() != null && !beakerParser.getDbURI().getUser().isEmpty()) { if(info == null){ info = new Properties(); info.put("user", beakerParser.getDbURI().getUser()); info = new Properties(); info.put("password", beakerParser.getDbURI().getPassword()); try (Connection connection = info != null ? ds.getDriver().connect(beakerParser.getDbURI().getActualConnectionString(), info) : ds.getConnection()) { this.connection = connection; connection.setAutoCommit(false); List<Object> resultsForOutputCell = new ArrayList<>(); Map<String, List<Object>> resultsForNamspace = new HashMap<>(); connection.commit();
final String url = dbMetaData.getURL(); final Driver jdbcDriver = DriverManager.getDriver(url); final DriverPropertyInfo[] propertyInfo = jdbcDriver .getPropertyInfo(url, new Properties()); for (final DriverPropertyInfo driverPropertyInfo: propertyInfo)
Properties props = new Properties(); props.put("user", user); props.put("password", password); connection = driverObject.connect(url, props); } else { String exception = "GemFireBasicDataSource::getConnection:Url for the DataSource not available"; logger.info(exception); throw new SQLException(exception);
@Before public void setUp() throws Exception { //register the driver DriverManager.registerDriver(mockDriver); //set up the mocked driver driver = Mockito.mock(Driver.class); connection = Mockito.mock(Connection.class); Mockito.when(driver.acceptsURL(Mockito.startsWith(DB_URL))).thenReturn(Boolean.TRUE); //tell the driver manager we can handle this url Mockito.doAnswer((InvocationOnMock invocation) -> connection).when(driver).connect(Mockito.startsWith(DB_URL), Mockito.any(Properties.class)); //go ahead and get a connection Mockito.doAnswer((InvocationOnMock invocation) -> null).when(connection).setAutoCommit(Matchers.anyBoolean()); //resolve some weird sporatic mockito issue that pops up sometimes Mockito.doAnswer((InvocationOnMock invocation) -> null).when(connection).clearWarnings(); //resolve some weird sporatic mockito issue that pops up sometimes final PreparedStatement createDatabasePreparedStatement = Mockito.mock(PreparedStatement.class); //temporary mock for creating the database Mockito.when(connection.prepareStatement(Mockito.startsWith("CREATE DATABASE IF NOT EXISTS"))).thenReturn(createDatabasePreparedStatement); Mockito.when(createDatabasePreparedStatement.execute()).thenReturn(Boolean.TRUE); final PreparedStatement createTablePreparedStatement = Mockito.mock(PreparedStatement.class); //temporary mock for creating the table Mockito.when(connection.prepareStatement(Mockito.startsWith("CREATE TABLE IF NOT EXISTS"))).thenReturn(createTablePreparedStatement); //create our class under test final Properties properties = new Properties(); mysqlDataStore = new MysqlDataStore(DB_URL, "dbName", "tableName", properties); //verify construction Mockito.verify(driver, Mockito.atLeastOnce()).connect(Mockito.startsWith(DB_URL), Mockito.any(Properties.class)); Mockito.verify(createDatabasePreparedStatement).execute(); //make sure we called execute. This also verifies that the prepared statement was correctly constructed. Mockito.verify(createTablePreparedStatement).execute(); //make sure we called execute. This also verifies that the prepared statement was correctly constructed. }
Properties info = new Properties(); info.put("user", getUserId()); info.put("password", getPassword()); Connection conn = getDriver().connect(getUrl(), info); throw new SQLException("No suitable Driver for " + url); conn.setAutoCommit(autocommit); return conn; } catch (SQLException e) { throw new BuildException(e, getLocation()); log("Failed to connect: " + e.getMessage(), Project.MSG_WARN); return null;
static void initRealDriverAndConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException { CoreFactory.REALDRIVER = (Driver) Class.forName(PROPERTIES.getDriverName()).newInstance(); final Properties p = new Properties(); p.setProperty("user", PROPERTIES.getUsername()); p.setProperty("password", PROPERTIES.getPassword()); CoreFactory.REALCONNECTION = REALDRIVER.connect(PROPERTIES.getUrl(), p); if (CoreFactory.REALCONNECTION == null) { //fix bug #1: NullPointerException with connection String for wrong driver throw new SQLException("OQT detected driver initialization failure. Is the given driver suited for the given connection String ? " + PROPERTIES.getDriverName() + " <-> " + PROPERTIES.getUrl()); } CoreFactory.REALCONNECTION.setReadOnly(true); }
proxyDriver.getMajorVersion(); proxyDriver.getMinorVersion(); proxyDriver.jdbcCompliant(); proxyDriver.getParentLogger(); proxyDriver.getPropertyInfo( "jdbc:proxy::jdbc:drill:zk=local", new Properties() ); final DatabaseMetaData dbMetaData = proxyConnection.getMetaData(); assertThat( dbMetaData, instanceOf( DatabaseMetaData.class ) ); assertThat( dbMetaData, notNullValue() ); assertThat( proxyConnection.getMetaData(), sameInstance( dbMetaData ) ); assertThat( catalogsResultSet.getMetaData(), sameInstance( rsMetaData ) );
try { Driver driverInstance = (Driver) d.newInstance(); return driverInstance.connect(url, prop); /*fix issue #695 with drivers with the same Context context = (Context) d.newInstance(); DataSource ds = (DataSource) context.lookup(url); String user = prop.getProperty("user"); String password = prop.getProperty("password"); if (StringUtils.isNullOrEmpty(user) && StringUtils.isNullOrEmpty(password)) { return ds.getConnection(); return DriverManager.getConnection(url, prop); return DriverManager.getConnection(url, prop);
@Override public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { String dbURL = info.getProperty(RAW_DATA_SOURCE_URL); if (dbURL == null) throw new SQLException("no rawDataSourceURL parameter"); info.remove(RAW_DATA_SOURCE_URL); return DriverManager.getDriver(url).getPropertyInfo(url, info); }
@Override public Connection getConnection(final String username, final String password) throws SQLException { final Properties cloned = (Properties) driverProperties.clone(); if (username != null) { cloned.put("user", username); if (cloned.containsKey("username")) { cloned.put("username", username); } } if (password != null) { cloned.put("password", password); } return driver.connect(jdbcUrl, cloned); }
public void setUseOracleImplicitCache(boolean useOracleImplicitCache) { if (this.useOracleImplicitCache != useOracleImplicitCache) { this.useOracleImplicitCache = useOracleImplicitCache; boolean isOracleDriver10 = isOracle() && this.driver != null && this.driver.getMajorVersion() == 10; if (isOracleDriver10 && useOracleImplicitCache) { this.getConnectProperties().setProperty("oracle.jdbc.FreeMemoryOnEnterImplicitCache", "true"); } else { this.getConnectProperties().remove("oracle.jdbc.FreeMemoryOnEnterImplicitCache"); } } }
log.debug("Unable to instantiate JDBC driver.", cn); SQLException ex = new SQLException(cn.getMessage()); ex.initCause(cn); throw ex; if (usr != null) properties.setProperty(PROP_USER, usr); if (pwd != null) properties.setProperty(PROP_PASSWORD, pwd); connection = driver.connect(driverURL, properties); } catch (Exception x) { if (log.isDebugEnabled()) { throw (SQLException)x; } else { SQLException ex = new SQLException(x.getMessage()); ex.initCause(x); throw ex;
/** {@inheritDoc} */ @Override public Connection getConnection(String username, String pwd) throws SQLException { Properties props = this.props.storeToProperties(); if (!F.isEmpty(username)) props.put("user", username); if (!F.isEmpty(pwd)) props.put("password", pwd); return IgniteJdbcThinDriver.register().connect(getUrl(), props); }
DriverManager.getDriver( "jdbc:drill:zk=local" ); throw new IllegalStateException( "Drill driver seems loaded already; can't test loading." ); e.getMessage(), equalTo( "No suitable driver" ) ); DriverManager.getConnection( "jdbc:drill:zk=local", null ); throw new IllegalStateException( "Drill driver seems loaded already; can't test loading." ); e.getMessage(), equalTo( "No suitable driver found for jdbc:drill:zk=local" ) ); e.getMessage(), equalTo( "No suitable driver" ) ); "jdbc:proxy:org.apache.drill.jdbc.Driver:jdbc:drill:zk=local" ); assertThat( driver.acceptsURL( "jdbc:proxy::jdbc:drill:zk=local" ), equalTo( true ) ); assertThat( driver.acceptsURL( "jdbc:drill:zk=local" ), equalTo( false ) ); assertThat( proxyConnection, notNullValue() ); final DatabaseMetaData dbMetaData = proxyConnection.getMetaData(); assertThat( dbMetaData, instanceOf( DatabaseMetaData.class ) );