Java 8 DataSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DataSource class.

This code example shows how to use the following methods: getConnection
    private InitialContext initialContext;
 
    @Test 
    public void testDeployedDataSource() throws Throwable { 
        final DataSource dataSource = (DataSource) initialContext.lookup("java:jboss/datasources/DeployedDS");
        Assert.assertNotNull(dataSource);
        Connection conn = dataSource.getConnection();
        ResultSet rs = conn.prepareStatement("select 1").executeQuery();
        Assert.assertTrue(rs.next());
    } 
 
 
    @Test 
    public void testDeployedXaDataSource() throws Throwable { 
        final DataSource dataSource = (DataSource) initialContext.lookup("java:/H2XADS");
        Assert.assertNotNull(dataSource);
        Connection conn = dataSource.getConnection();
        ResultSet rs = conn.prepareStatement("select 1").executeQuery();
        Assert.assertTrue(rs.next());
    } 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
 
    @Test 
    public void testDatasource() throws Exception { 
        InitialContext context = new InitialContext();
        DataSource ds = (DataSource) context.lookup(JNDI_NAME);
        Connection conn = ds.getConnection();
        ResultSet rs = conn.prepareStatement("select 1").executeQuery();
        Assert.assertTrue(rs.next());
    } 
} 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
    @Resource(lookup="org.jboss.as.test.integration.ee.datasourcedefinition.DataSourceBean/dataSource3") 
    private DataSource dataSource4;
 
 
    public void createTable() throws SQLException { 
        dataSource.getConnection().createStatement().execute("create table if not exists coffee(id int not null);");
    } 
 
    public void insert1RolledBack() throws SQLException { 
        dataSource.getConnection().createStatement().execute("insert into coffee values (1)");
        throw new RuntimeException("roll back");
    } 
 
    public void insert2() throws SQLException { 
        dataSource.getConnection().createStatement().execute("insert into coffee values (2)");
    } 
 
    public DataSource getDataSource() {
        return dataSource;
    } 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
            throw new IllegalArgumentException(
                "Must specify either dataSource or connection"); 
        } 
        Connection connection = null;
        try { 
            connection = dataSource.getConnection();
            if (connection == null) {
                // DataSource.getConnection does not return null. But 
                // a null value here would cause infinite recursion, so 
                // let's be cautious. 
                throw new IllegalArgumentException();
            } 
            final Dialect dialect =
                factory.createDialect(dataSource, connection);
 
            // Close the connection in such a way that if there is a 
            // SQLException, 
            // (a) we propagate the exception, 
            // (b) we don't try to close the connection again. 
            Connection connection2 = connection;
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
                return; 
            } 
 
            logger.info("Doing a DB operation using a DataSource"); 
            try { 
                conn = dataSource.getConnection();
                final PreparedStatement preparedStatement = conn.prepareStatement("select upper('foo')");
                preparedStatement.execute();
            } catch (SQLException e) {
                throw  new RuntimeException(e);
            } 
            logger.info("Done invoking DB operation. Holding on to connection till this method completes"); 
            logger.info("Invoking a BMT SLSB which will use UserTransaction"); 
            bmtslsb.doSomethingWithUserTransaction();
            logger.info("Sending a reply to destination " + replyTo);
            jmsMessagingUtil.reply(message);
        } catch (JMSException e) {
            throw new RuntimeException(e);
        } finally { 
            if (conn != null) {
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
			// Obtain JDBC Connection to operate on... 
			try { 
				ibatisCon = session.getCurrentConnection();
				if (ibatisCon == null) {
					springCon = (transactionAware ?
							dataSource.getConnection() : DataSourceUtils.doGetConnection(dataSource));
					session.setUserConnection(springCon);
					if (logger.isDebugEnabled()) { 
						logger.debug("Obtained JDBC Connection [" + springCon + "] for iBATIS operation");
					} 
				} 
				else { 
					if (logger.isDebugEnabled()) { 
						logger.debug("Reusing JDBC Connection [" + ibatisCon + "] for iBATIS operation");
					} 
				} 
			} 
			catch (SQLException ex) {
				throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", ex);
			} 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
		this.target = target;
	} 
 
	@Override 
	public Connection getConnection() throws SQLException {
		return target.getConnection();
	} 
 
	@Override 
	public Connection getConnection(String username, String password) throws SQLException {
		return target.getConnection(username, password);
	} 
 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
 
    @Test 
    public void testDataSourceDefinition() throws NamingException, SQLException { 
        DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName());
        DataSource ds = bean.getDataSource();
        ResultSet result = ds.getConnection().createStatement().executeQuery("select 1");
        Assert.assertTrue(result.next());
    } 
 
    @Test 
    public void testTransactionEnlistment() throws NamingException, SQLException { 
        DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName());
        try { 
            bean.insert1RolledBack();
            Assert.fail("expect exception");
        } catch (RuntimeException expected) {
        } 
        DataSource ds = bean.getDataSource();
        ResultSet result = ds.getConnection().createStatement().executeQuery("select id from coffee where id=1;");
        Assert.assertFalse(result.next());
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
    public void testDataSourceDefinition() throws Exception { 
        Connection conn = null;
 
        try { 
            trans.begin();
            conn = ds.getConnection();
            testConnection(conn, "select user()", user1);
            conn.close();
            conn = ds.getConnection(user2, user2);
            testConnection(conn, "select user()", user2);
        } finally { 
            if (conn != null) {
                try { 
                    conn.close();
                } catch (SQLException ignore) {
                    // Ignore 
                } 
            } 
            trans.commit();
        } 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getConnection
	protected final Log logger = LogFactory.getLog(getClass());
 
	@Override 
	public void shutdown(DataSource dataSource, String databaseName) {
		try { 
			Connection connection = dataSource.getConnection();
			Statement stmt = connection.createStatement();
			stmt.execute("SHUTDOWN");
		} 
		catch (SQLException ex) {
			if (logger.isWarnEnabled()) {
				logger.warn("Could not shutdown embedded database", ex);
			} 
		} 
	} 
 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 DataSource Questions & Answers:

See Code Examples for Java 8 DataSource Methods: