【问题标题】:snowflake temp table connection using JDBC使用 JDBC 的雪花临时表连接
【发布时间】:2021-06-07 04:23:38
【问题描述】:

我正在尝试使用 Mybatis 将临时值放入雪花临时表中。在 WebSphere Application Server 的 server.xml 文件中配置的连接详细信息。

理想情况下,值应保留在服务器请求级别。

但只要应用程序运行,临时表及其数据仍然可用。对于每个请求,我都能看到以前的插入数据。

相同的代码在 Oracle 全局临时表中运行良好。

public class TempDao{

@Inject
SqlSession sqlSession;

public int saveValues(List<TemporaryValue> values) {
        logger.debug("Saving items on temporary table");
        try {
            final Map<String, Object> parameters = new HashMap<>();
            parameters.put("jobList", values);
            return sqlSession.insert("com.some.sql.insertJobs", parameters);
        } catch (Exception e) {
            ExceptionUtils.propagate(e);
        }
        return 0;
    }


}

JNDI 连接:

<dataSource id="SnowflakeDataSource" jndiName="jdbc/BM_SF" maxPoolSize="100" queryTimeout="300s" statementCacheSize="1000" type="javax.sql.DataSource">
        <properties URL="jdbc:snowflake://adpdc_cdl.us-east-1.privatelink.snowflakecomputing.com" databaseName="***" password="****" schema="**" user="**" warehouse="****strong text**" />
        <jdbcDriver javax.sql.DataSource="net.snowflake.client.jdbc.SnowflakeBasicDataSource" libraryRef="SharedLib"/>
    </dataSource>

【问题讨论】:

  • 到底是什么问题?雪花临时表在创建它们的会话期间可用。它们在会话终止时被销毁。
  • 是的,你的问题是什么?
  • 你是怎么关闭JDBC连接的,能举个例子吗?
  • 听起来您的代码中有连接池,因此会话正在被重用(以节省连接设置时间),因此您的临时表的寿命比您预期的要长。
  • 是的,连接池中的所有连接的数据库会话 ID 都是相同的。雪花 JDBC 驱动程序似乎有些问题。

标签: jdbc snowflake-cloud-data-platform mybatis websphere-liberty snowflake-schema


【解决方案1】:

如果 Liberty 中的连接池干扰了 Snowflake 中会话的结束,则可以关闭它。查看我插入到您的配置 sn-p 中的agedTimeout 为 0(立即超时)的 connectionManager 元素,

    <dataSource id="SnowflakeDataSource" jndiName="jdbc/BM_SF" maxPoolSize="100" queryTimeout="300s" statementCacheSize="1000" type="javax.sql.DataSource">
        <connectionManager agedTimeout="0"/>
        <properties URL="jdbc:snowflake://adpdc_cdl.us-east-1.privatelink.snowflakecomputing.com" databaseName="***" password="****" schema="**" user="**" warehouse="****strong text**" />
        <jdbcDriver javax.sql.DataSource="net.snowflake.client.jdbc.SnowflakeBasicDataSource" libraryRef="SharedLib"/>
    </dataSource>

【讨论】:

  • 谢谢@njr。现在它正在工作。但是在生产中关闭连接池绝对不是一个好的选择
猜你喜欢
  • 1970-01-01
  • 2022-07-22
  • 2020-04-26
  • 2020-12-24
  • 2021-04-09
  • 1970-01-01
  • 2022-01-14
  • 2021-07-22
  • 1970-01-01
相关资源
最近更新 更多