我已经为MySQL设置了JOOQ。各种表的编译已完成,现在我尝试运行以下查询:
dsl.selectFrom(WALLPAPER).where(WALLPAPER.PARENT_ID.eq(id)).orderBy(WALLPAPER.VIEW_ORDER).fetchInto(WallpaperItem.class);
但我不断收到这个错误
"org.springframework.jdbc.BadSqlGrammarException: jOOQ; bad SQL grammar [select "library"."wallpaper"."id", "library"."wallpaper"."category_name", "library"."wallpaper"."icon", "library"."wallpaper"."view_order", "library"."wallpaper"."parent_id" from "library"."wallpaper" where "library"."wallpaper"."parent_id" = cast(? as int) order by "library"."wallpaper"."view_order" asc]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '."wallpaper"."id", "library"."wallpaper"."category_name", "library"."wallpaper' at line 1
可能是什么问题?
生成的SQL "name"
对模式/表/列名称使用双引号()。这就是导致MySQL语法错误的原因,MySQL希望使用反引号(`name`
)来引用名称。
生成双引号的原因是因为您为dsl
引用配置了错误SQLDialect
,即使用以外的东西SQLDialect.MYSQL
。例如:
DSLContext dsl = DSL.using(connection, SQLDialect.MYSQL);