MySQL Connector/J v5.x 升级:查询现在返回 byte[] 而不是 String

MySQL Connector/J v5.x upgrade: query now returning byte[] instead of String

我刚刚从

为我的应用程序更新了 JDBC 驱动程序
mysql-connector-java-3.1.12-bin.jar 

mysql-connector-java-5.1.34-bin.jar.

使用 v3.x 驱动程序,这种查询有效:

select concat("<a href>", count(sakila.payment.payment_id), "</a>") 
from sakila.payment;

但现在使用新的 v5.x 驱动程序,查询仅适用于 cast()。

select cast(concat("<a href>", count(sakila.payment.payment_id), "</a>")
as char(30)) from sakila.payment;

MySQL 数据库中是否有我可以更改的 属性? 我不想像这样更改数百个查询。

我怀疑您将不得不硬着头皮更新代码。有一个错误报告 here 似乎符合您的情况,该错误报告的状态是 "Won't fix"。开发人员的回复([2007 年 4 月 4 日 17:43] Reggie Burnett)是:

This is something that we can't really fix. Let me explain.

MySQL has several issues when it comes to reporting whether a result if binary or not. This was very bad on MySQL versions prior to 5.0 but it's still a problem even today. The SQL you reported is returned by MySQL as binary when it obviously is not. The connector can't know for sure. With 5.0.5 and 5.0.6, we tried to make a "best guess" but that code caused more problems than it solved, so with 5.0.7 we have rolled it out. Your SQL will return string properly with 5.0.7, but that doesn't mean it's fixed. In fact, it returns string because we are ignoring the binary flag so that means you could generate valid SQL that should return binary and 5.0.7 will return string.

Until the server is fixed, the connector just can't always do the right thing. I hope this has cleared it up somewhat.