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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-10 05:10:52 +0000
Seen: 12 times
Last updated: Jul 10 '23
What is the process to integrate SQLiter in KMM for both Android and IOS?
Can a transitive dependency in gradle be made exclusively for runtime purposes?
Why can't IntelliJ IDEA detect the Kotlin multiplatform library?
How do compileSdkVersion and targetSdkVersion differ from each other?
What does the error message "Failed to apply plugin [id 'com.jfrog.artifactory']" mean?
Why doesn't the Android Studio display the layout preview once MaterialCalendarView has been added?
How to update the outdated WebSecurityConfigurerAdapter in Spring Boot?