Tag Archives: SQLState: 42000

SQL Error: 1064, SQLState: 42000 [Three Methods to Solve]

If you accidentally use the keywords of the database, you will report the error “SQL error: 1064, sqlstate: 42000”

There are three solutions

1.Enclose the table name or field name in square brackets ([])

XML configuration:

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

Note:

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

2. Enclose the table name or field name with two accents (‘). The accented key is the key to the left of the “1” key and the key to the top of the “tab” key on the keyboard. This symbol is also known as “inverted quotation marks.”

XML configuration:

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

Note:

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

3. Use double quotation marks (“) to enclose the table name or field name

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

Note:

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