2

I am trying to connect to Snowflake using HikariPool. I am using SpringBoot and Gradle.

I added these dependencies to Gradle

implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'
implementation 'net.snowflake:snowflake-jdbc:3.12.16'
implementation group: 'com.zaxxer', name: 'HikariCP', version: '5.0.0'

And config file looks like this:

@Slf4j
@Configuration
public class SnowflakeRepositoryConfig {

    @Bean
    JdbcTemplate jdbcTemplate(@Value("${repository.snowflake.url}") String jdbcUrl,
                              @Value("${repository.snowflake.user}") String user,
                              @Value("${repository.snowflake.password}") String password){
        
        log.info("-----Configuring JDBCTemplate------");
        HikariConfig config = new HikariConfig();
        config.setDriverClassName("net.snowflake.client.jdbc.SnowflakeDriver");
        config.setJdbcUrl(jdbcUrl);
        config.setUsername(user);
        config.setPassword(password);
        HikariDataSource ds = new HikariDataSource(config);

        return new JdbcTemplate(ds);
    }
}

Application.yml

repository:
  snowflake:
    url: jdbc:snowflake://nw99383.eu-west-2.snowflakecomputing.com/?db=TEST_DB&warehouse=SF_TUTS_WH&schema=PUBLIC&tracing=ALL
    user: ****
    password: ****

And I am getting following error:

13:56:42.353 [main] ERROR net.snowflake.client.core.HttpUtil - Response status line reason: Forbidden
13:56:42.358 [main] ERROR net.snowflake.client.core.HttpUtil - Response content: <html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
</body>
</html>

13:56:43.371 [main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
net.snowflake.client.jdbc.SnowflakeSQLException: JDBC driver encountered communication error. Message: HTTP status=403.
user9347049
  • 1,927
  • 3
  • 27
  • 66

1 Answers1

2

Could you please update Snowflake account URL and try: nw99383.eu-west-2.aws.snowflakecomputing.com/

FKayani
  • 981
  • 1
  • 5
  • 10
  • I did and I have this error now: `Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class` – user9347049 Oct 18 '21 at 12:10
  • Please check if this resolution helps: https://www.baeldung.com/spring-boot-failed-to-configure-data-source – FKayani Oct 18 '21 at 12:12
  • I have specified `config.setDriverClassName("net.snowflake.client.jdbc.SnowflakeDriver");`and also have it in my application.yml file – user9347049 Oct 18 '21 at 12:14
  • Not a hikaripool user but got the below post with a connection snippet that sounds to work with Snowflake. please review: https://stackoverflow.com/questions/53845645/creating-custom-connection-pool-in-spring-boot-application – FKayani Oct 18 '21 at 12:19
  • I fixed my url like you said and added `@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})`from example that you sent me. I was tring to implement that one in first place. Now It works Thank you! – user9347049 Oct 18 '21 at 12:30