SQL Error: 1064, SQLState: 42000

你不当心使用了数据库的关键字 那么就会报这个错误 “SQL Error: 1064, SQLState: 42000错误”数据库

解决方法有三种:this

1、将表名或字段名用方括号([])括起来。code

xml配置:xml

<property name="desc" type="string" >   
<column name="[DESC]" length="255" not-null="true" />   
</property>

注解:get

@Column(name = "[DESC]", nullable = false)   
public String getDesc() { return this.desc; }

2、将表名或字段名用两个重音符号(`)括起来 重音符号键便是键盘上“1”键左边的、“Tab”键上边的那个键。此符号亦被称为“反向引号”。string

xml配置:配置

<property name="desc" type="string" >   
<column name="`DESC`" length="255" not-null="true" />   
</property>

注解:方法

@Column(name = "`DESC`", nullable = false)   
public String getDesc() { return this.desc; }

3、将表名或字段名用双引号(")括起来 xml配置:数据

<property name="desc" type="string" >   
<column name='"DESC"' length="255" not-null="true" />  
 </property>

注解:键盘

@Column(name = "\"DESC\"", nullable = false)   
public String getDesc() { return this.desc; }
相关文章
相关标签/搜索