首页 > 解决方案 > H2 failing to process valid MySQL - CONVERT(images.X USING UTF8) as X

问题描述

At my wit's end trying to figure this one out. It doesn't help that "convert" is such a generic word. I have a legacy app with working MySQL, but the database code is untested. I'm trying to add unit tests using an H2 DB. Getting the following error for my query:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT ...<verbose query>

When I remove this part of the query, it works: CONVERT(images.USER_DATA USING UTF8) as USER_DATA, though of course other things fail.

Is there a way to get H2 to recognize the CONVERT function or maybe another good way of converting this data?

Test properties:

images.jdbc.url=jdbc:h2:mem:images;MODE=MYSQL;INIT=RUNSCRIPT FROM 'classpath:init.sql'
images.driverClassName=org.h2.Driver

标签: mysqlh2

解决方案


问题最终是数据库将 BLOB 用于 json 而不是 TEXT。改变了,然后我不必再担心这个了。


推荐阅读