Best code examples for Java 8 DataSource class (javax.sql.DataSource)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DataSource class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 DataSource examples from Open Source projects
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
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
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
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
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
Related Java 8 DataSource Questions & Answers:
See Code Examples for Java 8 DataSource Methods: