在使用jOOQ从名为user
的表中进行选择时,我得到以下异常:
jOOQ; bad SQL grammar [insert into user (user_id, account_type) values (?, ?)]; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"
我的jOOQ设置为:
private static final Settings jooqSettings = new Settings()
.withRenderSchema(false)
.withRenderNameStyle(RenderNameStyle.LOWER);
我从中创建DSLContext
并在事务中构造查询,如下所示:
ctx.insertInto(USER)
.set(USER.USER_ID, userId)
.set(USER.ACCOUNT_TYPE, "U")
.execute()
USER
导入为<jooq-generated-package>.tables.USER
。
jOOQ是否有配置属性来转义表名(全部或仅保留关键字)?我在文档或来源中找不到任何内容。
答案 0 :(得分:2)
嗯,你通过设置RenderNameStyle.LOWER
来解决这个问题...那是怎么回事:)
通过删除该设置或将其设置为RenderNameStyle.QUOTED
,jOOQ将围绕所有标识符生成这些双引号。
<simpleType name="RenderNameStyle">
<restriction base="string">
<!--
Render object names quoted, as defined in the database. Use this
to stay on the safe side with case-sensitivity and special
characters. For instance:
Oracle : "SYS"."ALL_TAB_COLS"
MySQL : `information_schema`.`TABLES`
SQL Server: [INFORMATION_SCHEMA].[TABLES]
-->
<enumeration value="QUOTED"/>
<!--
Render object names, as defined in the database. For instance:
Oracle : SYS.ALL_TAB_COLS
MySQL : information_schema.TABLES
SQL Server: INFORMATION_SCHEMA.TABLES
-->
<enumeration value="AS_IS"/>
<!--
Force rendering object names in lower case. For instance:
Oracle : sys.all_tab_cols
MySQL : information_schema.tables
SQL Server: information_schema.tables
-->
<enumeration value="LOWER"/>
<!--
Force rendering object names in upper case. For instance:
Oracle : SYS.ALL_TAB_COLS
MySQL : INFORMATION_SCHEMA.TABLES
SQL Server: INFORMATION_SCHEMA.TABLES
-->
<enumeration value="UPPER"/>
</restriction>
</simpleType>
添加更多文档