1 | initial version |
To establish a JDBC connection between a Spring Boot application and Snowflake, you will need to follow these steps:
Add the Snowflake JDBC driver to your project's classpath using Maven or Gradle.
Maven:
<dependency>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc</artifactId>
<version>version_number_here</version>
</dependency>
Gradle:
implementation 'net.snowflake:snowflake-jdbc:version_number_here'
Configure the Snowflake JDBC driver in your application.yml or application.properties file. You will need to provide your Snowflake account information, including the account name, username, password, and a role.
Example configuration in application.yml:
spring:
datasource:
url: jdbc:snowflake://youraccount.region.snowflakecomputing.com/?user=username&password=password&role=rolename
driver-class-name: net.snowflake.client.jdbc.SnowflakeDriver
username: username
password: password
Use Spring's JdbcTemplate or NamedParameterJdbcTemplate to execute SQL queries against your Snowflake database.
Example usage in a Spring Boot controller:
@RestController
public class MyController {
private final JdbcTemplate jdbcTemplate;
public MyController(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@GetMapping("/customer")
public List<Customer> getCustomer() {
return jdbcTemplate.query("SELECT * FROM mydatabase.customer", new BeanPropertyRowMapper<>(Customer.class));
}
}
Note: replace "mydatabase.customer" with your actual Snowflake database.table.
Confirm that your Snowflake account's IP whitelist includes the IP address where your Spring Boot application is running.