/** * Create a new <C>java.sql.Connection</C> for this JDBC source. * @return * @throws SQLException */ public Connection getConnection() throws SQLException { return dataSource.getConnection(); }
public synchronized Connection getConnection() { try { return dataSource.getConnection(); } catch (SQLException e) { throw new RuntimeException(e); } } }
public static Connection getConnection( LogChannelInterface log, DatabaseMeta dbMeta, String partitionId, int initialSize, int maximumSize ) throws Exception { lock.lock(); try { if ( !isDataSourceRegistered( dbMeta, partitionId ) ) { addPoolableDataSource( log, dbMeta, partitionId, initialSize, maximumSize ); } } finally { lock.unlock(); } BasicDataSource ds = dataSources.get( getDataSourceName( dbMeta, partitionId ) ); return ds.getConnection(); }
@Override public Connection getConnection() throws SQLException { if (getDriverClassName() == null) { synchronized (this) { if (getDriverClassName() == null) { initializeDataSource(); } } } return super.getConnection(); }
@Override public Connection getConnection() throws ProcessException { try { if (ugi != null) { try { return ugi.doAs((PrivilegedExceptionAction<Connection>) () -> dataSource.getConnection()); } catch (UndeclaredThrowableException e) { Throwable cause = e.getCause(); if (cause instanceof SQLException) { throw (SQLException) cause; } else { throw e; } } } else { getLogger().info("Simple Authentication"); return dataSource.getConnection(); } } catch (SQLException | IOException | InterruptedException e) { getLogger().error("Error getting Hive connection", e); throw new ProcessException(e); } }
return ugi.doAs((PrivilegedExceptionAction<Connection>) () -> dataSource.getConnection()); } catch (UndeclaredThrowableException e) { Throwable cause = e.getCause(); return dataSource.getConnection();
public final class Database { private static final BasicDataSource dataSource = new BasicDataSource(); static { dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/data"); dataSource.setUsername("USERNAME"); dataSource.setPassword("PASSWORD"); } private Database() { // } public static Connection getConnection() throws SQLException { return dataSource.getConnection(); } }
ds.setPassword(""); ds.setUrl("jdbc:mysql://127.0.0.1:3306/test"); final Connection conn = ds.getConnection(); conn.createStatement().execute("truncate table test_table");
/** * <ul> * <li>Create the in-memory database and connect * <li>Create tables for snapshots and daily_paritions * <li>Attach all user defined functions from {@link SqlUdfs} * </ul> * */ @BeforeClass public void setup() throws SQLException { basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); basicDataSource.setUrl("jdbc:derby:memory:derbypoc;create=true"); Connection connection = basicDataSource.getConnection(); connection.setAutoCommit(false); this.connection = connection; execute("CREATE TABLE Snapshots (dataset_path VARCHAR(255), name VARCHAR(255), path VARCHAR(255), ts TIMESTAMP, row_count bigint)"); execute("CREATE TABLE Daily_Partitions (dataset_path VARCHAR(255), path VARCHAR(255), ts TIMESTAMP)"); // Register UDFs execute("CREATE FUNCTION TIMESTAMP_DIFF(timestamp1 TIMESTAMP, timestamp2 TIMESTAMP, unitString VARCHAR(50)) RETURNS BIGINT PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.apache.gobblin.data.management.retention.sql.SqlUdfs.timestamp_diff'"); }
BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("oracle.jdbc.driver.OracleDriver") ds.setUsername("scott"); ds.setPassword("tiger"); ds.setUrl(connectURI); ... Connection conn = ds.getConnection();
public DataSource createNewDataSource(Map params) throws IOException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName((String) DRIVERCLASS.lookUp(params)); dataSource.setUrl((String) JDBC_URL.lookUp(params)); dataSource.setUsername((String) USERNAME.lookUp(params)); dataSource.setPassword((String) PASSWORD.lookUp(params)); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setMaxActive(((Integer) MAXACTIVE.lookUp(params)).intValue()); dataSource.setMaxIdle(((Integer) MAXIDLE.lookUp(params)).intValue()); // check the data source is properly setup by trying to gather a connection out of it Connection conn = null; try { conn = dataSource.getConnection(); } catch (SQLException e) { throw new DataSourceException( "Connection pool improperly set up: " + e.getMessage(), e); } finally { // close the connection at once if (conn != null) try { conn.close(); } catch (SQLException e) { } } return dataSource; }
Connection connection = bds.getConnection(); DelegatingConnection dc = (DelegatingConnection) connection; Connection underlyingOlapConnection = dc.getInnermostDelegate();
@Override public Connection getConnection() throws Exception { return __ds.getConnection(); } }
public synchronized Connection getConnection() throws JdbcException { try { return this.ds.getConnection(); } catch (Exception e) { e.printStackTrace(); LOG.error("getConnection()", e); throw new JdbcException(e); } }
public Connection getConnection() throws SQLException { Connection conn = null; try { conn = ds.getConnection(); } finally { logStatistics(); } return conn; }
ds.setAccessToUnderlyingConnectionAllowed(true); Connection conn = ds.getConnection(); UnWrapper uw = DataSourceFinder.getUnWrapper(conn); assertNotNull(uw);
conn = dataSource.getConnection(); } catch (Exception e) { throw new DataSourceException("Connection test failed ", e);
private Connection getConnection() throws SQLException { ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUsername(user); ds.setPassword(pass); ds.setUrl(connurl); return ds.getConnection(); }
BasicDataSource ds= new BasicDataSource(); ds.setDriverClassName("org.postgresql.Driverr"); ds.setUrl("jdbc:postgresql://localhost/testdb"); ds.setUsername("dbuser"); ds.setPassword("dbpassword"); Connection connection = ds.getConnection();
private Connection getConnection() throws SQLException { ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUsername(user); ds.setPassword(pass); ds.setUrl(connurl); return ds.getConnection(); }