I stumbled upon Netbeans + JDBC + Amazon Athena

There are samples all over the place, but I didn't have much knowledge, so I made a note based on the stumbling block.

Premise

For the time being, let's assume that you can execute SQL from the Web console. The DB name is logs.

Create a bucket in Region US Standard

I get the result of running it via JDBC, but it's mandatory to save it to S3. And it seems to be useless (it will be an error) unless it is a region where Amazon Athena works properly. Create an S3 bucket with the region ʻUS Standard`.

Project creation

Launch Netbeans and start a new project> Java> Java application

Copy and paste the code

I referred to JDBC connection to Amazon Athena | Developers.IO.

Copy and paste.

Authentication settings

It seems that authentication can specify the constructor of ʻaws_credentials_provider_class by passing a value to the property ʻaws_credentials_provider_arguments in the set of properties passed to the JDBC driver.

It seems ... but I couldn't use it because of various reasons, so I will use this access key and secret access key.

Accessing Amazon Athena with JDBC — User Guide

With reference to the above page, the access key was set in the property ʻuser, and the secret access key was set in the same password`.

    info.put("s3_staging_dir", "s3://us-standar-region-phx-athena");
    info.put("user", "AWSACCESSKEYID");
    info.put("password", "AWSSECRETACCESSKEY");

Add library

-Bring the JDBC driver from Accessing Amazon Athena with JDBC — User Guide -Bring the AWS SDK from AWS SDK for Java | AWS --In the logging mode, an error occurred if this class was not available, so if necessary Apache Commons Logging --Download Apache Commons Logging Bring commons-logging-1.2-bin.zip from .cgi)

Unzip the above three and add each jar to the project. Right click on the project in Netbeas> Properties> Library> Add JAR / Folder> 3 times

SQL execution

The default database is specified correctly on the Web console, but you have to specify it properly via this. (Because you can specify the default DB, you should do that)

For example

select * from target_table limit 3;

Is

select * from logs.target_table limit 3;

Like this.

Recommended Posts

I stumbled upon Netbeans + JDBC + Amazon Athena
What I stumbled upon when installing Laravel-filemanager
[Beginner] I stumbled upon launching a project with Rails6
Note that I stumbled upon building the Rails environment
What I stumbled upon when installing Ruby on Ubuntu
What I stumbled upon in the ActiveModel :: Serializer test