问题描述:
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 不支持。

在JDK的规范中运行期重定义一个类必须准循以下原则

  1. 不允许新增、修改和删除成员变量
  2. 不允许新增和删除方法
  3. 不允许修改方法签名

参考:

Java反射-修改字段值, 反射修改static final修饰的字段:http://www.cnblogs.com/noKing/p/9038234.html

MyCat不支持毫秒 bug fix的更多相关文章

  1. MyCat不支持的SQL语句

    SELECT: Ø 跨分片(实体库)的交叉查询 Ø 跨节点的联合查询 (如用户库的表和平台库的表做联合查询) INSERT: Ø 插入的字段不包含分片字段 (如插入tbl_user_base_info ...

  2. 【独家】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 ...

  3. 【独家】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解读 在 ...

  4. 【独家】K8S漏洞报告 | 近期bug fix解读

    安全漏洞CVE-2019-3874分析 Kubernetes近期重要bug fix分析 Kubernetes v1.13.5 bug fix数据分析 ——本周更新内容 安全漏洞CVE-2019-387 ...

  5. K8S漏洞报告 | 近期bug fix解读&1.13主要bug fix汇总

    K8s近期漏洞详解 Kubernetes仪表盘漏洞(CVE-2018-18264) 因为这一漏洞,用户可以“跳过”登录过程获得仪表盘所使用的自定义TLS证书.如果您已将Kubernetes仪表盘配置为 ...

  6. Spider Studio 新版本 (20140109) - 修复浏览器对部分网页不支持的BUG

    SS对部分网页中引用的jquery.js有冲突, 会造成网页部分JS效果无法正常执行. 本次版本对其进行了修正, 优化了浏览器的脚本引用机制, 修正了这个BUG.

  7. oslo.messaging 1.8.0 bug fix and blueprint

    1366597 由于amqp_auto_delete可配置,但是NotifierPublisher使用的是没有在配置中获取而使用的默认的False,即非auo_delete,因而在用户配置了amqp_ ...

  8. [Bug FIX]安装 account_check_writing模块后采购收据打印报错的问题

    大写金额没填报错 修改:report_check.xml文件,把<span t-esc="fill_stars(o.amount_in_word)"/>一行替换为 &l ...

  9. NGUI UIGrid 动态刷新布局 && BUG FIX

    /// <summary> /// "1" => 对应的一个UISpirte,"1234" => 对应四个预设 /// </sum ...

随机推荐

  1. Linux学习23-Xftp上传文件显示乱码问题

    前言 当我们在windows新建一个文件,里面有中文时,使用Xftp上传到linux服务器上,会出现乱码问题. Windows的默认编码为GBK Linux的默认编码为UTF-8 Xftp上传文件乱码 ...

  2. js动画--一个小bug处理下

    对于上面的课程我们很好的处理了一个小bug,那么我们现在讲程序进行优化一下,前一节的程序中,我们处理处理的属性都是写死了的.为了我们能够很好的对某个属性进行操作的话.我们这样来设置. js文件 win ...

  3. linux定时任务(转)

    转自:https://www.cnblogs.com/intval/p/5763929.html linux 系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非 ...

  4. C++将模板的声明和定义放置在同一个头文件里

    1. 一个类: 头文件用于保存类的声明:定义文件保存类的实现.   2. 分离编译模式: 允许在一个编译单元(.cpp文件)中定义函数.类型.类对象等,然后在另一个编译单元中引用它们.编译器处理完所有 ...

  5. oc语言的特征

    类型结构+运行时 内存管理:引用计数与析构 并发:gcd 函数式:block

  6. learning shell monitor prog function

    [Purpose]        Shell script monitor prog function   [Eevironment]        Ubuntu 16.04 bash env   [ ...

  7. Xamarin.Forms一些常见问题

    安装 1.查看Xaramin.Forms的版本 在vs项目中查看引用的包(Xamarin.Forms)的版本,或者直接进文件夹看 C:\Microsoft\Xamarin\NuGet\xamarin. ...

  8. Singer 修改tap-s3-csv 支持minio 连接

    singer 团队官方处了一个tap-s3-csv 的tap,对于没有使用aws 的人来说并不是很方便了,所以简单修改了 下源码,可以支持通用的s3 csv 文件的处理,同时发布到了官方pip 仓库中 ...

  9. VUE的生命周期——钩子函数

  10. Tecplot显示周期和对称算例

    源视频链接:https://pan.baidu.com/s/1HdU3nsti8qLZhXvISxsSFA 提取码: 3kfu 模型链接:https://pan.baidu.com/s/1CQCGL7 ...