mysql connector 6.0.6 getString ArrayIndexOutOfBoundsException

mysql


发表于 2017-04-08 13:32


今天将connector从5.1.10升级到了6.0.6之后发现查询数据时发生了ArrayIndexOutOfBoundsException异常, sql语句部分如下:

    SELECT
    art.id AS art_id,
    art.content,
    art.pubDate,
    art.lastModifyDate,
    art.title,
    art.isPrivate,
    art.hits,
    art.summary,
    art.art_level,
    art.art_status,
    art.art_from,
    art.editor,
    art.space_id,
    art.art_lock,
    art.art_alias,
    art.allowComment,
    sp.space_alias,
    sp.space_name,
    space_lock,
    sp.is_private AS space_is_private,
    GROUP_CONCAT(bt.tag_name) AS tags
    FROM
    blog_article art
    LEFT OUTER JOIN blog_space sp
    ON art.space_id = sp.id
    LEFT OUTER JOIN blog_article_tag bat ON
    bat.article_id = art.id
    LEFT OUTER JOIN blog_tag bt ON bat.tag_id =
    bt.id

发现在取tags字符串的时候就会发生这个异常,debug一番之后也没有什么结果,google之后发现这本身就是mysql connector的一个bug,并且该bug发生的条件比较苛刻(可是我偏偏就碰到了。。):

  1. connection created with parameter ‘useServerPrepStmts=true’
  2. ResultSet contains a column with blob or text type
  3. Value of a last column in this ResultSet is NULL

bug地址:https://bugs.mysql.com/bug.php?id=84084

顺便说下useServerPrepStmts设置为true的作用,开启mysql服务器端的预编译sql语句功能,根据 https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration 提到的

~~useServerPrepStmts : Newer versions of MySQL support server-side prepared statements, this can provide a substantial performance boost. Set this property to true.

设置该选项为true可以获得一定的性能提升

最后无奈之下换回了5.1.41,其实5.1是我用的mysql(5.7)的推荐版本 https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-versions.html

QQ截图20170408134331.png


搜索