Connect to Athena Tables from Java Spring

Amazon Athena is an interactive query service that allows you to use standard SQL to view and analyze data in your organization's Tetra Data Lake S3 bucket. This page describes how to connect to your Athena tables from the Java Spring third-party tool.

Before You Begin

Before you can use Java Spring as a third-party tool to connect to Athena tables, you must have:

Connect to Athena Tables from Java Spring

To connect to Athena tables from Java Spring, you must configure a data source. After you configure the data source, you can use it with the jdbcTemplate as any other JDBC data source.

Example of a Java Spring configuration:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
public class ApplicationConfig {
    @Autowired
    private Environment env;

    @Bean
    public DataSource dataSource(){
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.simba.athena.jdbc.Driver));
        dataSource.setUrl(env.getProperty("jdbc.url"));
        dataSource.setUsername(env.getProperty("jdbc.username"));
        dataSource.setPassword(env.getProperty("jdbc.password"));
        // Without this property, Athena will not work
        Properties props = new Properties();
        props.put("S3OutputLocation",env.getProperty("jdbc.S3OutputLocation"));
        dataSource.setConnectionProperties(props);

        return dataSource;
    }
}