mysql8.0可以用druid吗_不支持Mysql8.0.11的XA

针对MySQL8.0.11版本与Druid的兼容性问题,可以通过在Druid源码中添加特定分支判断来解决报错,并使XA事务正常工作。具体做法包括在`createXAConnection`方法中,根据MySQL版本调用不同的连接获取方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@wenshao

com.alibaba.druid.util.MySqlUtils中的createXAConnection方法添加一个分支判断(直接拷贝==6的情况,并稍作修改),暂时可以解决报错,并且XA事务也可正常使用了:

`

if (major == 6) {

....

}else if (major == 8) {

if (method_6_getValue == null && !method_6_getValue_error) {

try {

class_6_connection = Class.forName("com.mysql.cj.jdbc.JdbcConnection");

method_6_getPropertySet = class_6_connection.getMethod("getPropertySet");

method_6_getBooleanReadableProperty = Class.forName("com.mysql.cj.conf.PropertySet").getMethod("getBooleanReadableProperty", String.class);

method_6_getValue = Class.forName("com.mysql.cj.conf.ReadableProperty").getMethod("getValue");

} catch (Exception ex) {

ex.printStackTrace();

method_6_getValue_error = true;

}

}

try {

// pinGlobalTxToPhysicalConnection

boolean pinGlobTx = (Boolean) method_6_getValue.invoke(

method_6_getBooleanReadableProperty.invoke(

method_6_getPropertySet.invoke(physicalConn)

, "pinGlobalTxToPhysicalConnection"

)

);

if (pinGlobTx) {

try {

if (method_6_getInstance == null && !method_6_getInstance_error) {

class_6_suspendableXAConnection = Class.forName("com.mysql.cj.jdbc.SuspendableXAConnection");

method_6_getInstance = class_6_suspendableXAConnection.getDeclaredMethod("getInstance", class_6_connection);

method_6_getInstance.setAccessible(true);

}

} catch (Throwable ex) {

ex.printStackTrace();

method_6_getInstance_error = true;

}

return (XAConnection) method_6_getInstance.invoke(null, physicalConn);

} else {

try {

if (method_6_getInstanceXA == null && !method_6_getInstanceXA_error) {

class_6_JDBC4SuspendableXAConnection = Class.forName("com.mysql.cj.jdbc.MysqlXAConnection");

method_6_getInstanceXA = class_6_JDBC4SuspendableXAConnection.getDeclaredMethod("getInstance", class_6_connection, boolean.class);

method_6_getInstanceXA.setAccessible(true);

}

} catch (Throwable ex) {

ex.printStackTrace();

method_6_getInstanceXA_error = true;

}

return (XAConnection) method_6_getInstanceXA.invoke(null, physicalConn, Boolean.FALSE);

}

} catch (InvocationTargetException e) {

Throwable cause = e.getCause();

if (cause instanceof RuntimeException) {

throw (RuntimeException) cause;

}

} catch (Exception e) {

e.printStackTrace();

method_6_getInstance_error = true;

}

}

`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值