MyCat不支持毫秒 bug fix
问题描述:
mysql jdbc的驱动(mysql-connector-java-5.1.34.jar)设置的服务器的版本号最低是5.6.4才不会截取时间毫秒,但是现在取的是mycat 的版本号 5.5.8-mycat-1.5.3.0-RELEASE-20170927190645 ,而不是实际的服务器版本5.6.21-log,所以时间精度丢失了
利用反射修改 JDBC4PreparedStatement 属性
public class JDBC4PreparedStatementWrapper extends JDBC4PreparedStatement {
public JDBC4PreparedStatementWrapper(MySQLConnection conn, String catalog) throws SQLException {
super(conn, catalog);
}
public JDBC4PreparedStatementWrapper(MySQLConnection conn, String sql, String catalog) throws SQLException {
super(conn, sql, catalog);
}
public JDBC4PreparedStatementWrapper(MySQLConnection conn, String sql, String catalog, PreparedStatement.ParseInfo cachedParseInfo) throws SQLException {
super(conn, sql, catalog, cachedParseInfo);
}
protected void detectFractionalSecondsSupport() throws SQLException {
this.serverSupportsFracSecs = this.connection != null;
System.out.println("=======================>true");
}
}
public class MyCatBugFixBean implements InitializingBean {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void afterPropertiesSet() throws Exception {
try {
Field f1 = PreparedStatement.class.getDeclaredField("JDBC_4_PSTMT_2_ARG_CTOR");
Field f2 = PreparedStatement.class.getDeclaredField("JDBC_4_PSTMT_3_ARG_CTOR");
Field f3 = PreparedStatement.class.getDeclaredField("JDBC_4_PSTMT_4_ARG_CTOR");
f1.setAccessible(true);
f2.setAccessible(true);
f3.setAccessible(true);
Field modifiers1 = f1.getClass().getDeclaredField("modifiers");
modifiers1.setAccessible(true);
modifiers1.setInt(f1, f1.getModifiers() & ~Modifier.FINAL);
Field modifiers2 = f2.getClass().getDeclaredField("modifiers");
modifiers2.setAccessible(true);
modifiers2.setInt(f2, f2.getModifiers() & ~Modifier.FINAL);
Field modifiers3 = f3.getClass().getDeclaredField("modifiers");
modifiers3.setAccessible(true);
modifiers3.setInt(f3, f3.getModifiers() & ~Modifier.FINAL);
f1.set(null, JDBC4PreparedStatementWrapper.class.getConstructor(new Class[]{MySQLConnection.class, String.class}));
f2.set(null, JDBC4PreparedStatementWrapper.class.getConstructor(new Class[] { MySQLConnection.class, String.class, String.class }));
f3.set(null, JDBC4PreparedStatementWrapper.class.getConstructor(new Class[] { MySQLConnection.class, String.class, String.class, PreparedStatement.ParseInfo.class }));
modifiers1.setInt(f1, f1.getModifiers() & ~Modifier.FINAL);
modifiers2.setInt(f2, f2.getModifiers() & ~Modifier.FINAL);
modifiers3.setInt(f3, f3.getModifiers() & ~Modifier.FINAL);
} catch (Exception e) {
// fix bug 异常
logger.error("fix mycat 不支持毫秒异常", e);
}
}
}
注:
运行时动态替换类的方法行不通。
PreparedStatement 拷贝后编译报错,所以运行时动态替换 PreparedStatement#detectFractionalSecondsSupport() 行不通。
运行时动态替换 JDBC4PreparedStatement 会更改类的定义(重写 detectFractionalSecondsSupport() 方法), JDK 不支持。
- 不允许新增、修改和删除成员变量
- 不允许新增和删除方法
- 不允许修改方法签名
参考:
Java反射-修改字段值, 反射修改static final修饰的字段:http://www.cnblogs.com/noKing/p/9038234.html
MyCat不支持毫秒 bug fix的更多相关文章
- MyCat不支持的SQL语句
SELECT: Ø 跨分片(实体库)的交叉查询 Ø 跨节点的联合查询 (如用户库的表和平台库的表做联合查询) INSERT: Ø 插入的字段不包含分片字段 (如插入tbl_user_base_info ...
- 【独家】K8S漏洞报告 | 近期bug fix解读&1.9.11主要bug fix汇总
*内容提要: 1. Kube-proxy长连接优雅断开机制及IPVS模式实现 2. 10/29--11/19 bug fix汇总分析 3. 1.9.11重要bug fix汇总 在本周的跟踪分析中,以1 ...
- 【独家】K8S漏洞报告|近期bug fix解读&1.11主要bug fix汇总
内容提要: 1. 高危漏洞CVE-2018-1002105深度解读 2. 11/19--12/11 bug fix汇总分析 3. 1.11重要bug fix解读 4. 1.9重要bug fix解读 在 ...
- 【独家】K8S漏洞报告 | 近期bug fix解读
安全漏洞CVE-2019-3874分析 Kubernetes近期重要bug fix分析 Kubernetes v1.13.5 bug fix数据分析 ——本周更新内容 安全漏洞CVE-2019-387 ...
- K8S漏洞报告 | 近期bug fix解读&1.13主要bug fix汇总
K8s近期漏洞详解 Kubernetes仪表盘漏洞(CVE-2018-18264) 因为这一漏洞,用户可以“跳过”登录过程获得仪表盘所使用的自定义TLS证书.如果您已将Kubernetes仪表盘配置为 ...
- Spider Studio 新版本 (20140109) - 修复浏览器对部分网页不支持的BUG
SS对部分网页中引用的jquery.js有冲突, 会造成网页部分JS效果无法正常执行. 本次版本对其进行了修正, 优化了浏览器的脚本引用机制, 修正了这个BUG.
- oslo.messaging 1.8.0 bug fix and blueprint
1366597 由于amqp_auto_delete可配置,但是NotifierPublisher使用的是没有在配置中获取而使用的默认的False,即非auo_delete,因而在用户配置了amqp_ ...
- [Bug FIX]安装 account_check_writing模块后采购收据打印报错的问题
大写金额没填报错 修改:report_check.xml文件,把<span t-esc="fill_stars(o.amount_in_word)"/>一行替换为 &l ...
- NGUI UIGrid 动态刷新布局 && BUG FIX
/// <summary> /// "1" => 对应的一个UISpirte,"1234" => 对应四个预设 /// </sum ...
随机推荐
- iodine dig A
(base) bonelee@bonelee-VirtualBox:~/Desktop$ dig paeadgpy.abc.com @45.32.247.94 ; <<>> D ...
- httprunner学习9-完整的用例结构(yaml&json)
前言 前面几篇零散的学了一些httprunner的知识点,那么一个完整的 YAML/JSON 用例文件包含哪些关键字呢? 测试用例结构 在 HttpRunner 中,测试用例组织主要基于三个概念: 测 ...
- 项目Beta冲刺(团队)--6/7
课程名称:软件工程1916|W(福州大学) 作业要求:项目Beta冲刺 团队名称:葫芦娃队 作业目标:进行新一轮的项目冲刺,尽力完成并完善项目 团队博客 队员学号 队员昵称 博客地址 04160242 ...
- wordpress数字分页列表导航实现
前面我们用了自定义的方式来实现wordpress数字分页,其实wordpress是已经有集成了Numbered Pagination相关的函数,我们直接调用就可以.具体实现方法如下代码调用 <? ...
- Redis主从复制之哨兵模式(sentinel)
介绍:反客为主的自动版,能够后台监控主机是否故障,如果故障了根据投票数自动将从库转换为主库 调整结构:6379带着80.81 自定义的/myredis目录下新建sentinel.conf文件,名字绝不 ...
- c语言的#和##的用法
#include <stdio.h> #define ADD(A,B) printf(#A " + " #B " = %d\n",((A)+(B)) ...
- arduino 开发视频
http://blog.uctronics.com/downloads/shields/ArduCAM_Camera_Shield_V2_DS.pdf http://www.arducam.com/k ...
- be of + 名词
语法: “be of +抽象名词(词组)” 表示主语的某种形状或特征,相当于 "be+形容词" 例如: be of value=be valuable : be of inter ...
- Python3.x保留字(33个)
- [WEB安全]源码泄露总结
原文链接:https://blog.csdn.net/qq_36869808/article/details/88895109 源码泄露总结: svn源码泄露:https://blog.csdn.ne ...