我的环境
> Java 5
>春天2.5.5
> DBCP DataSource(org.apache.commons.dbcp.BasicDataSource)
> MySQL
类似帖子
链接
我的问题
>我需要在我的连接上设置时区,旨在防止处理TIMESTAMP列时的转换.
我的想法/研究
> DBCP连接池没有提及时区周围的任何内容. LINK
>我调查和认为是oK的内容在THIS帖子中描述,举例说明:
destroy-method="close">
求助区:)
>但这不行!
>我想要的是一种简单的方法,优先使用Spring在jdbc连接上配置时区.
提前感谢任何帮助/提示/建议/知识分享
解:
我的解决方案基于此帖子收集的提示!谢谢大家!
(...)
@Override
public Connection getConnection() {
Connection conn = null;
Statement statement = null;
try {
conn = super.getConnection();
statement = conn.createStatement();
statement.execute("SET time_zone = \'" + timezone+"\'");
} catch (SQLException e) {
LOG.fatal("Error while SET time_zone", e);
} finally {
try {
statement.close();
} catch (SQLException e) {
LOG.warn("Error while closing statement", e);
}
}
if(LOG.isDebugEnabled())
LOG.debug("SET time_zone("+timezone+") for connection, succeed!");
return conn;
}
(...)
在我的Spring配置文件中:
(...)
(...)
我希望这篇文章可以帮助将来的某个人.有什么问题我!