【问题标题】:Setting connection timezone dynamically with Spring and c3p0 and MySQL使用 Spring 和 c3p0 和 MySQL 动态设置连接时区
【发布时间】:2013-01-05 03:04:18
【问题描述】:

我想以 c3p0 作为连接池动态设置 MySQL JDBC 连接的时区。要为给定的 MySQL JDBC 连接设置时区,我知道我可以使用“SET time_zone = '+02:00';”,但是如果我在从池中获取的连接上设置它,我假设连接将具有这个时区当它被归还给池并给一个新请求时,女巫请求连接?!?我理解对了吗?

如果是,我如何以一种方式动态设置池连接将其时区恢复为原始时区(在我的情况下,我在 MySQL 和 JCM 中使用 UTC 作为默认值,在启动期间通过 TimeZone.setDefault(UTC)我的春天背景)。

这是我的(报告)道中的代码 sn-p

public TrafficDuringDayGroupedByPhoneEvent countAllSummariesForTimeReport(Integer childId, Date start, Date end, MessageType type, TimeZone timezone) {


    Integer[] res = {0, 0, 0, 0};
    Session session = getSession();

    //SET time_zone = '+02:00';
    String sql = "select count(calls.d), d from (SELECT  start_time, \n"
            + "(case when hour(start_time) >= 6 and  hour(start_time) < 9 then 'morning'\n"
            + "when hour(start_time) >= 9 and  hour(start_time) < 15 then 'day'\n"
            + "when hour(start_time) >= 15 and  hour(start_time) < 21 then 'aft'\n"
            + "when hour(start_time) >= 21 and  hour(start_time) <= 24 then 'night'\n"
            + "when hour(start_time) < 6 then 'night' end) as d\n" + "FROM bpr_report_event b inner join ";

    ....
}

我的问题与下面的问题类似,只是我想为每个连接动态设置它,而不是与下面问题中的人在同一个时区。

Setting connection timezone with Spring and DBCP and MySQL

【问题讨论】:

    标签: mysql jdbc c3p0 spring-jdbc


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2011-08-23
      • 2013-02-05
      • 2011-02-01
      • 2013-03-06
      • 2013-02-21
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 2010-12-03
      相关资源
      最近更新 更多